Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A variant of Fermat's Little Theorem states that $a^{p - 1} \equiv 1~mod~p$ if $a$ is not divisible by $p$.

Why is this last condition important? Why must $a$ and $p$ be relatively prime?

share|cite|improve this question
If $a$ is divisible by $p$, then $a^{p-1}\equiv 0\pmod p$. – Brian M. Scott May 12 '13 at 4:19
Beat me by 20 seconds @BrianM.Scott ;) – Alex Wertheim May 12 '13 at 4:21
up vote 6 down vote accepted

If $p$ divides $a$, then $a\equiv 0\bmod p$, so you will have $$a^{p-1}\equiv 0^{p-1}\equiv 0\not\equiv 1\bmod p.$$ If you prefer a statement of Fermat's little theorem that doesn't have this restriction: $$a^p\equiv a\bmod p$$ for any integer $a$ (regardless of whether it's relatively prime to $p$).

share|cite|improve this answer

If $a$ is divisible by $p$, then $a^{p-1} \equiv 0$ (mod $p)$.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.