Euler Totient Calculator
The first screen focuses on phi(n), the factor formula, and a preview of residues that are coprime to n.
Use this Euler Totient Calculator to enter values, adjust options, and review results in a compact responsive workspace.
Results are calculated automatically as you enter data.
The first screen focuses on phi(n), the factor formula, and a preview of residues that are coprime to n.
▼ See explanations and tips below ▼
Euler’s totient function, written as \(\varphi(n)\), counts how many integers are coprime to a positive integer \(n\). Two integers are coprime when their greatest common divisor is \(1\).
For example, the positive integers up to \(12\) that are coprime to \(12\) are:
Each of these has no common factor with \(12\) except \(1\), so:
The totient function is useful because it connects prime factorization, modular arithmetic, reduced residues, Euler’s theorem, and RSA-style arithmetic. Instead of asking only “what divides \(n\)?”, it asks “how many residues remain usable when numbers that share factors with \(n\) are removed?”
A common definition is:
In words: \(\varphi(n)\) is the number of integers from \(1\) through \(n\) whose greatest common divisor with \(n\) is \(1\). For \(n>1\), this is the same as counting the reduced residues from \(1\) through \(n-1\).
Euler’s totient function matters because it turns a counting problem into a structure problem. At first, \(\varphi(n)\) looks like something you would find by checking every number from \(1\) to \(n\). But once you know the prime factorization of \(n\), you can compute \(\varphi(n)\) directly.
That is important in number theory because many modular arithmetic results depend on coprime residues. For example, Euler’s theorem says that if \(a\) is coprime to \(n\), then:
This theorem generalizes Fermat’s little theorem from prime moduli to many composite moduli. The same family of ideas also appears in introductory explanations of RSA-style arithmetic, where a modulus is often written as a product of two distinct primes.
The direct way to find \(\varphi(n)\) is to test each number from \(1\) to \(n\) and count the values that have greatest common divisor \(1\) with \(n\). That method is easy to understand, but it is not the most efficient way to compute the function.
The faster method uses the distinct prime factors of \(n\). If \(p\) runs over the distinct prime numbers that divide \(n\), then:
Where:
This formula works because every prime factor of \(n\) removes a predictable fraction of the residues. If \(2\) divides \(n\), then multiples of \(2\) are not coprime to \(n\). If \(3\) also divides \(n\), then multiples of \(3\) are also excluded. The product formula combines these exclusions in a way that avoids double-counting.
If the prime factorization is:
then the totient can also be written as:
Both forms give the same result. The product form with \(n\prod(1-1/p)\) is often the easiest to apply once the distinct prime factors are known.
Start with the numbers from \(1\) through \(12\):
Keep only the numbers whose greatest common divisor with \(12\) is \(1\):
There are \(4\) such numbers, so:
Now check the same value with the prime factorization formula. Since:
we use the distinct prime factors \(2\) and \(3\):
If \(n\) is prime, every positive integer less than \(n\) is coprime to \(n\). For \(n=13\), the coprime values are:
There are \(12\) values, so:
For any prime \(p\):
This is why prime values sit on the line \(\varphi(n)=n-1\) in a totient trend graph.
For \(n=8\), the prime factorization is:
Using the product formula:
The reduced residues are:
Even though \(8\) has only one distinct prime factor, that prime factor still removes all even residues.
A semiprime is a product of two primes. If \(n\) is the product of two distinct primes \(p\) and \(q\), then:
and the totient becomes:
For example, let:
Then:
This shortcut works for products of two distinct primes. It should not be used unchanged when \(n\) is not of the form \(pq\) with distinct prime factors.
The value \(\varphi(1)\) is conventionally taken to be:
This case is special because there are no positive integers less than \(1\). In modular arithmetic, modulo \(1\) also behaves differently from ordinary moduli because every integer is congruent to \(0\) modulo \(1\). For calculator results, treat \(n=1\) as a special convention rather than as a typical counting example.
The main result \(\varphi(n)\) is a count. It tells you how many residues are coprime to \(n\).
A larger value of \(\varphi(n)\) means that more residues remain usable modulo \(n\). A smaller value means that more residues share factors with \(n\) and are excluded from the reduced residue system.
For a prime \(n\), the result is as large as possible for \(n>1\):
For a composite \(n>1\), the result is lower because at least some values share a nontrivial factor with \(n\).
| Result item | What it means |
|---|---|
| \(\varphi(n)\) | The number of residues coprime to \(n\) |
| Prime factorization | The prime powers used to compute the totient |
| Coprime count | Another way to describe the same total counted by \(\varphi(n)\) |
| Reduced residues | Values that are coprime to \(n\), shown as a preview when the list is long |
| Product formula | The substitution of the prime factors into the totient formula |
| Badges | Number-type labels, such as prime, prime power, square-free, or composite |
| Trend graph | A visual comparison of \(\varphi(n)\) values across nearby integers |
| Euler theorem example | A modular exponentiation example using one automatically selected coprime base |
| RSA connection | A helper for the semiprime formula when the factorization has exactly two distinct prime factors |
The reduced-residue preview is especially useful for small \(n\), where the full list is easy to inspect. For larger values, the preview may show only the first part of the reduced residue system, so the chips shown on screen may not be the complete list.
The trend graph helps explain the shape of the totient function. Prime numbers appear on the upper envelope \(\varphi(n)=n-1\). Composite numbers usually appear below that line because at least one nontrivial factor removes additional residues from the count.
A common mistake is confusing \(\varphi(n)\) with the number of divisors of \(n\). These are different questions. The totient function counts numbers that are coprime to \(n\); the divisor-counting function counts numbers that divide \(n\).
For example, \(12\) has \(6\) positive divisors:
But \(\varphi(12)=4\) because only:
are coprime to \(12\).
Another mistake is applying the RSA-style shortcut too broadly. The formula:
is for two distinct primes \(p\) and \(q\). It is not the right shortcut for a prime power such as \(p^2\), and it is not the right shortcut for a number with three or more distinct prime factors.
Users also sometimes expect the reduced-residue preview to list every residue. For large values of \(\varphi(n)\), the preview may be capped, so it should be read as a sample of the reduced residues rather than as a full list.
It is also easy to forget that the input must be a positive integer. Zero, negative numbers, decimals, blank entries, and non-numeric input do not fit the definition used here.
Finally, the Euler theorem card should be read as an example, not as a complete proof for every base. Euler’s theorem applies when the base is coprime to \(n\), but the calculator chooses one small coprime base automatically rather than letting the user test every possible base.
Use Euler’s totient function when you need to understand how many residues are coprime to a modulus.
Common uses include:
The function is especially helpful when a problem involves the phrase “relatively prime to \(n\)” or “invertible modulo \(n\).”
The main mathematical result is exact for accepted inputs. It is an integer count, not an estimate or a rounded decimal.
The calculator accepts plain decimal-digit positive integers up to \(1,000,000\). Values above that limit are not accepted so the calculation can remain responsive. Decimals, signs, and scientific notation are invalid rather than being converted into a nearby integer.
The trend slider uses integer values and is limited to a graph range from \(20\) to \(200\). Moving the slider also selects the corresponding value of \(n\), so it changes the calculation rather than only changing the graph display.
The reduced-residue list is a preview when the list is long. If more than \(80\) residues are available, only the first part is displayed.
The highly composite badge is checked only for values up to \(1,000\). For larger accepted inputs, the result explicitly says that this classification was not evaluated.
The RSA connection card is educational. It shows the direct semiprime formula only when \(n\) has exactly two distinct prime factors. This calculator is not a cryptographic key generator and should not be used to create real security parameters.
The Euler theorem example uses one automatically chosen coprime base. It is useful for seeing the theorem in action, but it is not a user-selected modular exponentiation tool.
\(\varphi(n)\) counts how many integers from \(1\) through \(n\) are coprime to \(n\). For \(n>1\), this is the same as counting the residues from \(1\) through \(n-1\) that have greatest common divisor \(1\) with \(n\).
If \(p\) is prime, none of the integers \(1,2,\ldots,p-1\) is divisible by \(p\). Each of them is therefore coprime to \(p\), so there are \(p-1\) coprime values.
Prime factors tell you exactly which residues must be excluded because they share a factor with \(n\). The product formula uses each distinct prime factor to remove the correct fraction of non-coprime residues.
No. \(\varphi(n)\) counts values that are coprime to \(n\), while the divisor count measures how many positive integers divide \(n\). For example, \(12\) has \(6\) positive divisors, but \(\varphi(12)=4\).
A reduced residue system modulo \(n\) is a complete set of residues that are coprime to \(n\), with no two values representing the same residue class modulo \(n\). Its size is \(\varphi(n)\).
Euler’s theorem says that if \(a\) is coprime to \(n\), then:
This means the totient gives an exponent that returns a coprime base to \(1\) modulo \(n\).
Euler’s totient function in this context is defined for positive integers. Decimals, zero, and negative values do not match that input domain, so they are not accepted.
For large values, the number of reduced residues can be long. The calculator previews the first residues and indicates when it is not showing the complete list.
Use this shortcut when \(p\) and \(q\) are distinct primes and \(n=pq\). For other factorizations, use the general product formula instead.
Books and Textbooks
Academic and Primary Sources