Maths WorkshopMaths problems with full solutions
Exercise 1280Number theory › Divisibility and gcdOlympiadAdded 4 Nov 2026

The gcd of 2ᵃ − 1 and 2ᵇ − 1

#gcd#Euclidean algorithm#divisibility

Statement

Let a,ba,b be positive integers. Prove that
gcd⁡(2a−1, 2b−1)=2gcd⁡(a,b)−1.\gcd(2^a-1,\,2^b-1)=2^{\gcd(a,b)}-1.
Deduce that 2a−12^a-1 divides 2b−12^b-1 if and only if aa divides bb.

Hint

Suppose a>ba>b. Write 2a−1=2a−b(2b−1)+(2a−b−1)2^a-1=2^{a-b}(2^b-1)+(2^{a-b}-1) and compare with the Euclidean algorithm.

Show solutionHide solution

Solution

Idea. The Euclidean algorithm on the exponents is mirrored by the Euclidean algorithm on the numbers 2k−12^k-1.

Key step. For a>ba>b,
2a−1=2a−b(2b−1)+(2a−b−1),2^a-1=2^{a-b}\bigl(2^b-1\bigr)+\bigl(2^{a-b}-1\bigr),
so gcd⁡(2a−1,2b−1)=gcd⁡(2b−1,2a−b−1)\gcd(2^a-1,2^b-1)=\gcd(2^b-1,2^{a-b}-1), because gcd⁡(u,v)=gcd⁡(v,u−qv)\gcd(u,v)=\gcd(v,u-qv) for any integer qq. Thus the pair of exponents (a,b)(a,b) is replaced by (b,a−b)(b,a-b).

Conclusion. Repeating the subtraction step, the exponents follow the subtractive Euclidean algorithm and end at (g,g)(g,g) with g=gcd⁡(a,b)g=\gcd(a,b) (or at (g,0)(g,0) if one uses gcd⁡(u,0)=u\gcd(u,0)=u, where 20−1=02^0-1=0). Hence the gcd equals 2g−12^g-1.

Divisibility. 2a−1∣2b−1  ⟺  gcd⁡(2a−1,2b−1)=2a−1  ⟺  2gcd⁡(a,b)−1=2a−1  ⟺  gcd⁡(a,b)=a  ⟺  a∣b2^a-1\mid2^b-1\iff\gcd(2^a-1,2^b-1)=2^a-1\iff2^{\gcd(a,b)}-1=2^a-1\iff\gcd(a,b)=a\iff a\mid b.

Check. gcd⁡(212−1,218−1)=gcd⁡(4095,262143)=63=26−1\gcd(2^{12}-1,2^{18}-1)=\gcd(4095,262143)=63=2^6-1 ✓.

Lesson. When a gcd involves a parametrised expression, show that the Euclidean algorithm on the parameter reproduces the Euclidean algorithm on the values.