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

I recently came upon a strange pattern, and have absolutely no idea why it exists. I was hoping for an explanation.

Let there be three integers: $p$, $a$ and $n$; $p$ is any prime number, while $a$ and $n$ are numbers such that $1\leq a < p$ and $1 \leq n < p$

Let Set $S$ be $\{{an^1\pmod p, an^2\pmod p, \dots, an^{p-1}\pmod p\}}$. Why is it that the number of distinct numbers in Set $S$ is always a divisor of $p-1$?

An example : Let $p$ be 7, $a$ be $3$ and $n$ be $2$.

Therefore Set S would be : $\{{3 * 2^1\pmod7,\dots,3* 2^6\pmod7\}}$

which equals to: $6\pmod 7$, $5\pmod7$, $3\pmod 7$, $6\pmod7$, $5\pmod7$, $3\pmod7$.

There are 3 distinct numbers in this set. $6$, or $p-1$, is divisible by $3$.

This is true for any prime $p$. Why is the number of distinct numbers in Set $S$ always a divisor of $p-1$?

I realize this is a seemingly random pattern, but I need to understand it to complete my paper.

share|cite|improve this question
Fixed link: Lagrange's theorem (group theory) – Rahul Apr 23 '12 at 6:00
up vote 2 down vote accepted

Without group theory:

Look at your 7, 3, 2 example. Note how the numbers go 6, 5, 3, 6, 5, 3; you get the distinct numbers 6, 5, 3, and then they repeat. Well, that always happens: you get a string of distinct numbers, and then that string repeats, exactly, until you get to the end. Since you write down $p-1$ numbers total, and the string repeates exactly until you have written down the $p-1$ numbers, the number of numbers in the string must be a factor of $p-1$.

Well, there are a few assertions in that paragraph that need to be proved. You don't need group theory to prove them, you can find the topic discussed (although not in exactly the terms I've used) in any introductory Number Theory text. I'm sorry, but I'm not up to writing it all out here.

share|cite|improve this answer
Thanks. Just one question: Why do you a string of distinct numbers? – user26649 Apr 23 '12 at 22:08
Not sure I understand your question. Do you mean, why do you get a string of distinct numbers? Well, you get a list of numbers, and they are distinct until there is a repeat. What I asserted without proof is that the first number to repeat is always the first number in the list, and that thereafter everything repeats exactly that first string of distinct numbers. If I have misunderstood your question, please try again. – Gerry Myerson Apr 24 '12 at 2:03
Sorry, stupid typo. That partially answered my question- I'm confused as to why it repeats after a number of distinct numbers that can divide $p-1$. As in why does it restart it's cycle after 3 distinct numbers? Why not 4 or some other number not a divisor of $p-1$? – user26649 Apr 24 '12 at 3:43
If it started cycling after some number of terms not a divisor of $p-1$, then you'd reach term number $p-1$ in the middle of a cycle. But there's a theorem that says that $n^p\equiv n\pmod p$, so in fact when you reach $p-1$ you have to be ready to start a new cycle, not be in the middle of an old one. This is called Fermat's little theorem, and is another one of those topics discussed in intro number theory texts. – Gerry Myerson Apr 24 '12 at 6:02
Awesome, thanks! – user26649 Apr 24 '12 at 13:09

Hint $\ $ Given you have no knowledge of group theory, you can employ these two simple facts.

$(1)\ \ \ \rm mod\ p\!:\ n^{p-1}\equiv 1\ \Rightarrow\:$ the order k of n divides $\rm p\!-\!1,\:$ i.e. $\:\!$ if $\rm\:k>0\:$ is least such that $\rm n^k\equiv 1\:$ then $\rm\:k\ |\ p\!-\!1.\:$ Thus the sequence of powers $\rm\:n,n^2,\ldots,n^{p-1}\:\!$ decomposes into the subsequence $\rm\:n,n^2,\ldots,n^k\!\equiv\! 1\:$ repeated $\rm\:(p\!-\!1)/k\:$ times.

$(2)\ \ $ The map $\rm\:x \to a\:\!x\:$ is $1\!-\!1$ since $\rm\:a\not\equiv 0\:$ $\Rightarrow$ $\rm\:a^{-1}\:$ exists mod $\rm p.\:$ Hence scaling all elements of the repeated subsequence by $\rm\: a\:$ preserves its length, i.e. the elements remain distinct. Note that the elements of the original subsequence are distinct, else $\rm\:n^i \equiv n^j\:$ for $\rm\:1\le i < j \le k\:$ yields $\rm\:n^{j-i}\equiv 1\:$ for $\rm\:0 < j\!-\!i < k,\:$ contra minimality of $\rm k$ (here, again, we've used the fact that $\rm\: mod\ p\!:\ n\not\equiv 0\:$ implies that $\rm\:n^{-1}$ exists, hence $\rm\:n\:$ is cancellable from both sides of a congruence).

share|cite|improve this answer

This is an example of Lagrange's theorem in group theory. The elements $an^k$ form a coset in the group $U_p$, the multiplicative group of the field of $p$ elements.

share|cite|improve this answer
... actually in the group $U_p$ (the nonzero integers mod $p$ under multiplication mod $p$, rather than all the integers mod $p$ under addition mod $p$). – Robert Israel Apr 23 '12 at 4:30
I have absolutely no knowledge about group theory (I do not even know what a group is). Can this be explained without group theory, or would I need to learn it? – user26649 Apr 23 '12 at 4:42
@Farhad: this is group theory. Any explanation of this phenomenon would constitute an explanation of (a small part of) group theory. – Qiaochu Yuan Apr 23 '12 at 5:03
@Qiaochu, sure, but the phenomenon was known long before there was any such discipline as group theory, and can be explained without any reference to group theory. – Gerry Myerson Apr 23 '12 at 5:07

Your Answer


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