# When is $a^k \pmod{m}$ a periodic sequence?

Let $a$ and $m$ be a positive integers with $a < m$. Suppose that $p$ and $q$ are prime divisors of $m$. Suppose that $a$ is divisible by $p$ but not $q$.

Is there necessarily an integer $k>1$ such that $a^k \equiv a \pmod{m}$?

Or is it that the best we can do is say there are $n>0$ and $k>1$ such that $a^{n+k} \equiv a^n \pmod{m}$

What can be said about $n$ and $k$?

EDIT: Corrected to have $k>1$ rather than $k>0$.

EDIT: The following paper answers my questions about $n$ and $k$ very nicely.
A. E. Livingston and M. L. Livingston, The congruence $a^{r+s} \equiv a^r \pmod{m}$, Amer. Math. Monthly $\textbf{85}$ (1978), no.2, 97-100.
It is one of the references in the paper Math Gems cited. Arturo seems to say essentially the same thing in his answer.

-
I'm not sure which answer to accept because they were all helpful. – reachout Jan 24 '12 at 1:12

A nice presentation of such semigroup generalizations of the Euler-Fermat theorem and related number theory is the following freely available paper

S. Schwarz, The role of semigroups in the elementary theory of numbers, Math. Slovaca, Vol. 31 (1981) pp. 369–395.

-
Thank you very much. – reachout Jan 24 '12 at 1:10

Sure there is, let $k=1$.

If the question is reworded, to $k>1$, then the answer is no, let $a=2$ and $m=12$.

For more general work along these lines, look for "least universal exponent" or "Carmichael function." This is the least number $\lambda(m)$ such that $a^{\lambda(m)}\equiv 1 \pmod{m}$ for all $a$ relatively prime to $m$.

We can find a $k$ such that $a^{\lambda(m)+k}\equiv a^k \pmod{m}$ for every $a$. This holds automatically if $a$ and $m$ are relatively prime. To take care of the not relatively prime cases, all we need to do is to make sure that for any prime $p$ that divides both $a$ and $m$, $a^k \equiv 0 \pmod{m}$. To make sure of this, let $k$ be the largest exponent that occurs in the prime power factorization of $m$.

-
Well spotted!${}{}$ – Arturo Magidin Jan 23 '12 at 20:28
Thanks you very much. – reachout Jan 24 '12 at 1:10

(Assuming you meant $k\gt 1$)

The best you can say say is that there are $n$ and $k$ such that $a^{n+k}\equiv a^n\pmod{m}$. And of course, there is a least $n$ for which there exist such $k$, and a least $k$ that make this true; in the sense that if $r$ and $s$ are any positive integers such that $a^r\equiv a^s\pmod{m}$, then $r,s\geq n$, and $r\equiv s\pmod{k}$. (These are the "cyclic monoids/semigroups".)

For example, $m=12$, $a=2$. Then $a^2\equiv 4\pmod{12}$, $a^3\equiv 8\pmod{12}$, $a^4\equiv 4\pmod{2}$, and you never get back to $2$.

The problem will arise whenever you have a prime $p$ that divides both $a$ and $m$, but the highest power of $p$ that divides $a$ is strictly smaller than the highest power of $p$ that divides $m$.

Consider the situation one prime at a time. If $\gcd(p,a)=1$, then there is a $k_p$ such that $a^{k_p}\equiv a\pmod{p^{r_p}}$, where $p^{r_m}$ is the exact power of $p$ that divides $m$. We know that $k_p$ divides $p^{r_p-1}(p-1)$, but in general we don't know more than that.

If $p|a$, let $p^{s_p}$ be the exact power of $p$ that divides $a$. If $n_p=\lceil \frac{r_p}{s_p}\rceil$ we have that $n_p$ is the smallest positive integer such that $a^{n_p+1}\equiv a_{n_p}\pmod{p^{r_p}}$, and moreover, $a$, $a^2,\ldots,a^{n_p}$ are pairwise distinct modulo $p^{r_p}$.

By the Chinese Remainder Theorem, $a^{n+k}\equiv a^n\pmod{m}$ if and only if $a^{n+k}\equiv a^n\pmod{p^{r_p}}$ for each prime $p$ that divides $m$. For primes that do not divide $a$, this implies that $k$ is a multiple of $k_p$; for primes that do divide $a$, this implies that $n\geq n_p$ and $k$ is arbitrary.

So you can say that $n\geq \max\{n_p \mid p|\gcd(a,m)\}$ and $\mathrm{lcm}\{k_p\mid p\text{ divides }m\text{ and }p\text{ does not divide }a\}$ divides $k$.

Conversely, if $n$ and $k$ satisfy those conditions, then the value of $n$ guarantees that $a^{n+k}\equiv a^n\pmod{p^{r_p}}$ for all primes that divide $\gcd(a,m)$; and the value of $k$ guarantees that $a^{n+k}\equiv a^n\pmod{p^{r_p}}$ for all primes that divide $m$ but not $a$.

-
Thank you very much. – reachout Jan 24 '12 at 1:10

This is related to a question of mine, namely To what divisors $a$ of $n$ can Euler's Theorem multiplied by $a$ be generalized, i.e. when is $a^{\phi(n)+1}\equiv a \pmod n$? and one answer is that $a^k$ and $m=\gcd(a,n)$ must be coprime, where $k=\phi(n)/\phi(m)$.

In your case, $n=pq$ with $p\neq q$ primes and $\gcd(a,n)=p=m$, therefore $k=\frac{\phi(pq)}{\phi(p)}=\frac{(p-1)(q-1)}{p-1} = q-1$, i.e.

$a^{q-1}\equiv a\pmod{pq}$ with $\gcd(a,pq)=p$ iff $a^{q-1}$ and $p$ are coprime or $a\equiv0\pmod{pq}$. Since $p$ divides $a$, the former cannot be the case and therefore the only possible solution is $a\equiv0\pmod{pq}$, which however means $a$ is also divided by $q$ which contradicts your assumption. Therefore, the answer to you question is "No".

-