$ n = a_k*10^k + ... + a_0*10^0 $
Say
$ \phi: Z \to Z_3 $
$ 10 \mapsto 1 $
n is divisible by 3 if and only if $ \phi(n) = 0 $
$ \phi(n) = \phi(a_k)*\phi(10)^k + ... + \phi(a_0)*\phi(10)^0 $
$ \phi(n) = \phi(a_k) + ... + \phi(a_0) $ (because 10 maps to 1, so $ \phi(10) = 1 $)
$ \phi(n) = \phi(a_k + ... + a_0) $
So if $ \phi(n) = 0 $, then $ \phi(a_k + ... + a_0) = 0 $.
$ \phi(a_k + ... + a_0) = 0 $ only when $ a_k + ... + a_0 $ is divisible by 3.