Fermat's Little Theorem says:
Theorem 1 (Fermat) If p is a prime number and (a, p)=1, that is a and p are relatively primes, then ap-1 ≡ 1 (mod p).
Euler gave a generalization of Fermat's theorem. His generalization will follow at once from next theorem, which is proceed by counting, using essentially the same argument as in finite integral domain. (See 69th and 70th articles.)
Lemma 2. The set Gn of nonzero elements of Zn that are not zero divisors forms a group under multiplication mudulo n.
Proof. First we must show that Gn is closed under multiplication modulo n. Let a, b∈Gn. If ab is not in Gn, then there would exist c in Zn such that c≠0 and (ab)c=0. Now (ab)c=0 implies that a(bc)=0. Since b∈Gn and c≠0, we have bc≠0 by definition of Gn. But then a(bc)=0 would imply that a not in Gn contrary to assumption. Note that we have shown that for any ring the set of elements that are not zero divisors is closed under multiplication. No structure of Zn other than ring structure has been involved so far.
We now show that Gn is a group. Of course, multiplication modulo n is associative, and 1∈Gn. It remains to show that for a∈Gn, there is b∈Gn such that ab=1. Let 1, a1, a2, …, ar be the elements of Gn. The elements a1, aa1, aa2, …, aar are all different, for if aai=aaj, then a(ai-aj)=0, and since a∈Gn and thus is not a zero divisor, we must have ai-aj=0 or ai=aj. Therefore by counting, we find that either a1=1, or some aai must be 1, so a has a multiplicative inverse. QED.
Let n be a positive integer. Let φ(n) be defined as the number of positive integers less than or equal to n and relatively prime to n. Note that φ(1)=1. For the zero divisors are precisely those nonzero elements that are not relatively prime to n in the ring Zn, φ(n) us the number of nonzero elements of Zn that are not zero divisors. This function φ is the Euler phi-function. We can now describe Euler's generalization of Fermat's theorem.
Theorem 3 (Euler) If a is an integer relatively prime to n, then aφ(n)-1 is divisible by n, that is, aφ(n) ≡ 1 (mod n).
Proof. If a is relatively prime to n, then the coset a+nZ containing a contains an integer b<n an relatively prime to n. Using the fact that multiplication of these cosets by multiplication modulo n of representatives is well-defined, we have aφ(n)≡bφ(n) (mod n). But by Lemma, b can be viewed as an element of the multiplicative group Gn of order φ(n) consisting of the φ(n) elements of Zn relatively prime to n. Thus bφ(n) ≡ 1 (mod n). QED.
Reference
John B. Fraleigh, A First Course in Abstract Algebra 7ed, Addison-Wesley
Geschrieben von Sooji Shin