Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to find the phi(18). Using an online calculator, it says it is 6 but im getting four.
The method I am using is by breaking 18 down into primes and then multiplying the phi(primes)

$$=\varphi (18)$$ $$=\varphi (3) \cdot \varphi(3) \cdot \varphi(2)$$ $$= 2 \cdot 2 \cdot 1$$ $$= 4$$

share|cite|improve this question
$\varphi(3^2) \ne \varphi(3) \cdot \varphi(3)$. – user61527 Mar 4 '14 at 3:39
If $p$ is prime, then $\varphi(p^k)=p^k-p^{k-1}$. This is because there are $p^k$ numbers between $0$ and $p^k-1$. Of these, $p^{k-1}$ are multiples of $p$, and the rest are relatively prime to $p$. – André Nicolas Mar 4 '14 at 3:44
This question is similar:… – Martin Sleziak Mar 4 '14 at 9:10
up vote 4 down vote accepted

Remember that you need to determine the prime factorization of $18$. That is, $18 = 3^2 \cdot 2$. Since $18 = 3^2 \cdot 2$, we have

$$\begin{aligned} \varphi(18) = \varphi(3^2) \cdot \varphi(2) &= (3^2 - 3)(2 - 1) = 6 \end{aligned}$$

So in general, if $k = p_1^{n_1}p_2^{n_2}\cdots p_s^{n_s}$, then we have

$$\varphi(k) = \varphi(p_1^{n_1})\varphi(p_2^{n_2})\cdots \varphi(p_s^{n_s}) = (p_1^{n_1} - p_1^{n_1 - 1})(p_2^{n_2} - p_2^{n_2 - 1})\cdots (p_s^{n_s} - p_s^{n_s - 1})$$

share|cite|improve this answer
thanks a lot! makes sense! – Krimson Mar 4 '14 at 3:58

The phi function is multiplicative, but not completely multiplicative: Thus if $a, b$ are relatively prime, we have that

$$\varphi(ab) = \varphi(a) \varphi(b)$$

but this is not necessarily true if $a$ and $b$ have a common prime factor. In particular, it's true that

$$\varphi(18) = \varphi(2) \varphi(9)$$

but not $\varphi(2) \varphi(3)^2$.

share|cite|improve this answer

Your multiplicative property is not necessarily true when the two numbers you're multiplying share a common factor. Here's the general formula: given $N = p_1^{q_1}p_2^{q_2}\cdots p_n^{q_n}$ (where $p_1, \ldots, p_n$ are distinct primes), we can find that $$ \phi(N) = N\left(1-\frac{1}{p_1}\right)\left(1-\frac{1}{p_2}\right)\cdots\left(1-\frac{1}{p_n}\right) $$

In the case of $18 = 2 \cdot 3^2$, this gives: $$ \phi(18) = 18\left(\frac{1}{2}\right)\left(\frac{2}{3}\right) = 6 $$ I leave the proof of this as an exercise (hint: consider (and enumerate) those numbers divisible by $p_1, p_2, \ldots, p_n$).

share|cite|improve this answer

By definition, $\varphi(18)$ is the number of elements in the set $$\{n : 1\leq n \leq 17, \text{ with } \gcd(n,18)=1\}=\{1,5,7,11,13,17\}.$$ Thus, $\varphi(18)=6$. Similarly, $\varphi(9)$ is the number of elements in the set $$\{n : 1\leq n \leq 8, \text{ with } \gcd(n,9)=1\}=\{1,2,4,5,7,8\},$$ so $\varphi(9)=6$, and not $4$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.