Ya que nadie ha mencionado teorema de Euler aquí hay otra respuesta.
Si $\gcd(a,30)=1$$a^{\varphi(30)} \equiv 1 \pmod{30}$$\varphi(30)=8$. O $30 \mid a^8-1$$a^{25}-a=a(a^{24}-1)=a(a^8-1)(a^{16}+a^8+1)$. Por lo tanto $30 \mid a\cdot(a^{24}-1)$
Si $\gcd(a,30)=d \in \{2,3,5,6,10,15,30\}$
- $d=30$ $30 \mid a \Rightarrow 30 \mid a\cdot (a^{24}-1)$
- en todos los demás casos $30=d\cdot d_1$, $d \mid a$ y $\gcd(d_1,a)=1$ $$a^{\varphi(d_1)} \equiv 1 \pmod{d_1} \tag{1}$$ or $30=d\cdot d_1 \mediados de los a\cdot (a^{\varphi(d_1)}-1)$. But $d_1 \en \{2,3,5,6,10,15\}$ as well and $\varphi(2)=1,\varphi(3)=2,\varphi(5)=4, \varphi(6)=2, \varphi(10)=4, \varphi(15)=8$ all are factors of $24$. Or $24=\varphi(d_1)\cdot p$ and from $(1)$ $$a^{24}\equiv a^{\varphi(d_1)\cdot q} \equiv 1^{q} \equiv 1 \pmod{d_1}$$ Thus $30=d\cdot d_1 \mediados de los a\cdot (a^{24}-1)$.