Let $N$ be a positive integer whose prime factorization is $N=p^aq^b$. The number of positive integers that do not exceed $N$, but are relatively prime to $N$ is given by the $\varphi$ function: $$\varphi(N)=N\left(1-\frac{1}{p}\right)\left(1-\frac{1}{q}\right)$$
Note that the result is only related to $N$'s prime factors, but not to their powers.
If $N$ has more than two prime factors, $p_1$, $p_2$, $\cdots$, $p_k$, then the result can be obtained by: $$\varphi(N)=N\left(1-\frac{1}{p_1}\right)\left(1-\frac{1}{p_2}\right)\cdots\left(1-\frac{1}{p_k}\right)$$
Tips: if you cannot remember the $\varphi$ function while solving a problem, use the inclusion and exclusion principle. However the $\varphi$ function has important applications in number theory and is worth memorizing.