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$$
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})$$