Cycle of Powers of Two
Find the remainder of \(2^{17}\) modulo \(5\).
List the first four powers of \(2\) modulo \(5\).
We get \(2,4,3,1\), then the cycle repeats with period \(4\). Since \(17\equiv1\pmod4\), \(2^{17}\equiv2\pmod5\).
Chapter
Theory
Powers modulo a number do not grow forever: residues begin to repeat. The olympiad task is usually not to “compute a huge power”, but to choose the right period: a short cycle, Fermat's little theorem, Euler's theorem, or the order of an element.
First look for a short cycle. If the modulus is prime, check Fermat. If the modulus is composite and the base is coprime to it, use Euler or split the modulus into parts.
If the exponent is huge, reduce it modulo a period. If the modulus is a prime \(p\), the period often divides \(p-1\). If the modulus is composite, first check \(\gcd(a,m)=1\); otherwise Euler's theorem is not available.
If a prime \(p\mid a^k-1\) appears, move to the order of \(a\) modulo \(p\). The order divides both \(k\) and \(p-1\), which often strongly restricts \(p\).
Examples
Sometimes the period is visible faster than any big theorem.
Problem. Find the remainder of \(3^{20}\) modulo \(7\).
We have \(3^1\equiv3\), \(3^2\equiv2\), \(3^3\equiv6\), \(3^6\equiv1\pmod7\). Since \(20\equiv2\pmod6\), \(3^{20}\equiv3^2\equiv2\pmod7\).
Comment. The period is \(6\), but it was enough to find the return to \(1\).
The last digit is the residue modulo \(10\).
Problem. Find the last digit of \(7^{2026}\).
The last digits of powers of \(7\) are \(7,9,3,1\), then the cycle repeats. The period is \(4\). Since \(2026\equiv2\pmod4\), the last digit is the second digit of the cycle, namely \(9\).
Comment. No need to compute the power; only the exponent modulo the period matters.
For a prime modulus, the exponent \(p-1\) often neutralises the problem.
Problem. Prove that \(11\mid 2^{10}-1\).
Since \(11\) is prime and \(11\nmid2\), Fermat's little theorem gives \(2^{10}\equiv1\pmod{11}\). Therefore \(11\mid2^{10}-1\).
Comment. It is important to check that the base is not divisible by \(11\).
Fermat lets us replace a large exponent by its remainder modulo \(p-1\).
Problem. Find the remainder of \(5^{100}\) modulo \(13\).
By Fermat, \(5^{12}\equiv1\pmod{13}\). Since \(100\equiv4\pmod{12}\), \(5^{100}\equiv5^4\pmod{13}\). Also \(5^2=25\equiv-1\pmod{13}\), so \(5^4\equiv1\pmod{13}\).
Comment. Sometimes after Fermat a small convenient square remains.
For the last two digits we work modulo \(100\), not only modulo \(10\).
Problem. Find the last two digits of \(7^{100}\).
Since \(\gcd(7,100)=1\), we can look for a cycle. Notice that \(7^2=49\), and \(7^4\equiv49^2=2401\equiv1\pmod{100}\). Hence \(7^{100}=(7^4)^{25}\equiv1\pmod{100}\). The last two digits are \(01\).
Comment. A short cycle is better than Euler's theorem here.
For a composite modulus, coprimality must be checked.
Problem. Find the remainder of \(3^{100}\) modulo \(35\).
\(\gcd(3,35)=1\), so Euler's theorem applies. \(\varphi(35)=\varphi(5)\varphi(7)=4\cdot6=24\). Since \(100\equiv4\pmod{24}\), we get \(3^{100}\equiv3^4=81\equiv11\pmod{35}\).
Comment. If the base and modulus were not coprime, this move would be illegal.
The order is the true period of powers returning to \(1\).
Problem. Find the order of \(2\) modulo \(9\).
Compute: \(2^1\equiv2\), \(2^2\equiv4\), \(2^3\equiv8\), \(2^4\equiv7\), \(2^5\equiv5\), \(2^6\equiv1\pmod9\). Since \(1\) did not occur earlier, \(\operatorname{ord}_9(2)=6\).
Comment. After this, \(2^n\equiv1\pmod9\) if and only if \(6\mid n\).
Fermat gives inverses modulo a prime.
Problem. Find the inverse of \(4\) modulo \(17\).
By Fermat, \(4^{16}\equiv1\pmod{17}\), so \(4^{15}\) is an inverse of \(4\). But direct computation is shorter: \(4\cdot13=52\equiv1\pmod{17}\). Therefore the inverse is \(13\).
Comment. The theorem explains existence, but a short calculation is often faster.
Problems
Find the remainder of \(2^{17}\) modulo \(5\).
List the first four powers of \(2\) modulo \(5\).
We get \(2,4,3,1\), then the cycle repeats with period \(4\). Since \(17\equiv1\pmod4\), \(2^{17}\equiv2\pmod5\).
Find the last digit of \(3^{25}\).
The last digits of powers of \(3\) have period \(4\).
The cycle of last digits is \(3,9,7,1\). Since \(25\equiv1\pmod4\), the last digit is \(3\).
Find the remainder of \(4^{12}\) modulo \(7\).
Check what \(4^3\) is modulo \(7\).
\(4^2=16\equiv2\pmod7\), \(4^3\equiv8\equiv1\pmod7\). Hence \(4^{12}=(4^3)^4\equiv1\pmod7\).
Prove that \(7\mid 3^6-1\).
Apply Fermat's little theorem.
The number \(7\) is prime and \(7\nmid3\). By Fermat's little theorem, \(3^6\equiv1\pmod7\). Therefore \(7\mid3^6-1\).
Explain why Euler's theorem cannot be applied to \(2^{10}\) modulo \(8\), and find the remainder.
Check \(\gcd(2,8)\).
\(\gcd(2,8)=2\ne1\), so Euler's theorem cannot be used. But \(2^3=8\equiv0\pmod8\), so every \(2^n\) with \(n\ge3\) is divisible by \(8\). Hence \(2^{10}\equiv0\pmod8\).
Find the remainder of \(5^{2026}\) modulo \(11\).
By Fermat, reduce the exponent modulo \(10\).
Since \(11\) is prime, \(5^{10}\equiv1\pmod{11}\). Also \(2026\equiv6\pmod{10}\), so \(5^{2026}\equiv5^6\). Now \(5^2\equiv3\), \(5^4\equiv9\), hence \(5^6\equiv9\cdot3=27\equiv5\pmod{11}\).
Find the remainder of \(2^{100}\) modulo \(13\).
Use \(2^{12}\equiv1\pmod{13}\).
By Fermat, \(2^{12}\equiv1\pmod{13}\). Since \(100\equiv4\pmod{12}\), \(2^{100}\equiv2^4=16\equiv3\pmod{13}\).
Find the remainder of \(7^{50}\) modulo \(9\).
Check \(7^3\) modulo \(9\).
\(7^2=49\equiv4\pmod9\), \(7^3\equiv4\cdot7=28\equiv1\pmod9\). Since \(50\equiv2\pmod3\), \(7^{50}\equiv7^2\equiv4\pmod9\).
Find the last two digits of \(3^{40}\).
Work modulo \(100\) and apply Euler's theorem.
\(\gcd(3,100)=1\), and \(\varphi(100)=40\). By Euler's theorem, \(3^{40}\equiv1\pmod{100}\). Thus the last two digits are \(01\).
Find the remainder of \(11^{2025}\) modulo \(12\).
Notice that \(11\equiv-1\pmod{12}\).
\(11\equiv-1\pmod{12}\). The exponent \(2025\) is odd, so \(11^{2025}\equiv(-1)^{2025}\equiv-1\equiv11\pmod{12}\).
Find the order of \(3\) modulo \(7\).
Compute powers until \(1\) appears for the first time.
\(3^1\equiv3\), \(3^2\equiv2\), \(3^3\equiv6\), \(3^4\equiv4\), \(3^5\equiv5\), \(3^6\equiv1\pmod7\). Since \(1\) did not appear earlier, the order is \(6\).
Find all positive \(n\) such that \(3^n\equiv1\pmod7\).
Use the order of \(3\) modulo \(7\).
From the previous problem, \(\operatorname{ord}_7(3)=6\). Therefore \(3^n\equiv1\pmod7\) if and only if \(6\mid n\). The answer is all positive multiples of \(6\).
Find the remainder of \(2^{2026}+3^{2026}\) modulo \(5\).
Both powers have period \(4\) modulo \(5\).
Since \(2026\equiv2\pmod4\), \(2^{2026}\equiv2^2\equiv4\pmod5\) and \(3^{2026}\equiv3^2\equiv9\equiv4\pmod5\). The sum is \(4+4=8\equiv3\pmod5\).
Prove that \(13\mid 5^{12k}-1\) for every positive integer \(k\).
First apply Fermat to \(5^{12}\).
Since \(13\) is prime and \(13\nmid5\), \(5^{12}\equiv1\pmod{13}\). Then \(5^{12k}=(5^{12})^k\equiv1^k\equiv1\pmod{13}\). Hence \(13\mid5^{12k}-1\).
Find the last two digits of \(9^{2026}\).
Compute the cycle of powers of \(9\) modulo \(100\).
\(9^1\equiv9\), \(9^2\equiv81\), \(9^3\equiv29\), \(9^4\equiv61\), \(9^5\equiv49\), \(9^6\equiv41\), \(9^7\equiv69\), \(9^8\equiv21\), \(9^9\equiv89\), \(9^{10}\equiv1\pmod{100}\). Since \(2026\equiv6\pmod{10}\), \(9^{2026}\equiv9^6\equiv41\pmod{100}\). The last two digits are \(41\).
Find the remainder of \(3^{2026}\) modulo \(28\).
Split the modulus \(28\) into \(4\) and \(7\).
Modulo \(4\), \(3^{2026}\equiv1\), since the exponent is even. Modulo \(7\), \(3^6\equiv1\), and \(2026\equiv4\pmod6\), so \(3^{2026}\equiv3^4=81\equiv4\pmod7\). We need a number congruent to \(1\) modulo \(4\) and to \(4\) modulo \(7\). It is \(25\). The answer is \(25\).
Prove that for every prime \(p\) and every integer \(a\), the number \(a^p-a\) is divisible by \(p\).
Split into the cases \(p\mid a\) and \(p\nmid a\).
If \(p\mid a\), then \(a^p-a\equiv0-0\equiv0\pmod p\). If \(p\nmid a\), Fermat gives \(a^{p-1}\equiv1\pmod p\). Multiplying by \(a\), \(a^p\equiv a\pmod p\). In both cases, \(p\mid a^p-a\).
Let \(p\) be prime and \(p\nmid a\). Prove that \(a^{p-2}\) is the inverse of \(a\) modulo \(p\).
Multiply \(a^{p-2}\) by \(a\).
By Fermat, \(a^{p-1}\equiv1\pmod p\). But \(a\cdot a^{p-2}=a^{p-1}\). Therefore \(a\cdot a^{p-2}\equiv1\pmod p\), so \(a^{p-2}\) is the inverse.
Find the inverse of \(7\) modulo \(13\).
You may compute directly or use \(7^{11}\).
Direct computation: \(7\cdot2=14\equiv1\pmod{13}\). Hence the inverse of \(7\) is \(2\). This agrees with Fermat: \(7^{11}\) must also be an inverse of \(7\).
Find the remainder of \(2^{1000}\) modulo \(31\).
Notice that \(2^5\equiv1\pmod{31}\).
\(2^5=32\equiv1\pmod{31}\). Since \(1000\) is divisible by \(5\), \(2^{1000}=(2^5)^{200}\equiv1\pmod{31}\).
Find all primes \(p\) such that \(p\mid 2^p+1\).
For odd \(p\), use \(2^p\equiv2\pmod p\).
For \(p=2\), \(2^2+1=5\), not divisible by \(2\). Let \(p\) be an odd prime. By Fermat in the form \(a^p\equiv a\pmod p\), \(2^p\equiv2\pmod p\). Then \(2^p+1\equiv3\pmod p\). For \(p\mid2^p+1\), we need \(p\mid3\), so \(p=3\). Check: \(2^3+1=9\), divisible by \(3\). The answer is \(p=3\).
Let \(p\) be an odd prime, \(p\mid a^2+1\), and \(p\nmid a\). Prove that \(p\equiv1\pmod4\).
From \(a^2\equiv-1\pmod p\), find the order of \(a\) modulo \(p\).
We have \(a^2\equiv-1\pmod p\). Then \(a^4\equiv1\pmod p\), but \(a^2\not\equiv1\pmod p\), since that would give \(-1\equiv1\pmod p\), hence \(p=2\). Thus the order of \(a\) modulo \(p\) is \(4\). The order divides \(p-1\), so \(4\mid p-1\), i.e. \(p\equiv1\pmod4\).
Find all primes \(p\) such that \(p\mid 3^p+2\).
Modulo \(p\), \(3^p\) is congruent to \(3\).
By Fermat, \(3^p\equiv3\pmod p\) for every prime \(p\). Hence \(3^p+2\equiv5\pmod p\). If \(p\mid3^p+2\), then \(p\mid5\), so \(p=5\). Check: \(3^5+2=243+2=245\), divisible by \(5\). The answer is \(p=5\).
Let \(n\ge1\), and let \(p\) be an odd prime divisor of \(2^{2^n}+1\). Prove that \(p\equiv1\pmod{2^{n+1}}\).
Consider the order of \(2\) modulo \(p\).
From the condition, \(2^{2^n}\equiv-1\pmod p\). Squaring gives \(2^{2^{n+1}}\equiv1\pmod p\). Thus the order of \(2\) modulo \(p\) divides \(2^{n+1}\). But it does not divide \(2^n\), because \(2^{2^n}\equiv-1\not\equiv1\pmod p\). Since all divisors of \(2^{n+1}\) are powers of two, the order is \(2^{n+1}\). The order of an element modulo prime \(p\) divides \(p-1\), hence \(2^{n+1}\mid p-1\). Therefore \(p\equiv1\pmod{2^{n+1}}\).
Ladders