Maths4UBETA

Maths4U · Learning together

Advanced GCD Problems

Notes

Key Idea

Strong gcd problems are rarely just computations. The main technique is to replace a pair of numbers by a simpler pair with the same gcd: subtract multiples, take linear combinations, use polynomial remainders, and reduce exponents.

Basic Facts

We use gcd⁡(a,b)=gcd⁡(a,b−ka) \gcd(a,b)=\gcd(a,b-ka) , gcd⁡(a,b)=gcd⁡(a,b mod a) \gcd(a,b)=\gcd(a, b \bmod a) , and the fact that if dd divides two numbers, then dd divides every integer linear combination of them. If gcd⁡(a,b)=1 \gcd(a,b)=1 and a∣bca\mid bc, then a∣ca\mid c. For powers, the key identity is gcd⁡(am−1,an−1)=agcd⁡(m,n)−1 \gcd(a^m-1,a^n-1)=a^{\gcd(m,n)}-1 .

When to Use This Method

Use gcd methods when a problem contains divisibility of two expressions, a condition like gcd⁡(f(n),g(n))>1 \gcd(f(n),g(n))>1 , powers am−1a^m-1, neighbouring terms of a sequence, or a request to find all parameters for which the common divisor is not one.

How to Recognise the Method

Look for a substitution by a remainder: if a divisor contains n+cn+c, replace nn by −c-c in the other expression. If powers have different exponents, apply the Euclidean algorithm to the exponents. If numbers are coprime, test whether a common prime divisor would be forced to divide both original numbers.

Typical Mistakes

Do not divide a congruence by a number before checking coprimality. Do not conclude from d∣abd\mid ab that d∣ad\mid a or d∣bd\mid b. In power problems, it is easy to prove only one direction; one must also show that the proposed gcd is maximal.

Mini-checklist

1. Which two expressions have a common divisor? 2. Can one expression be replaced by a linear combination? 3. Can a power or exponent be reduced? 4. What happens to a prime divisor? 5. Is there a coprimality condition? 6. Have all residues or parameters been checked?

Example 1. A Remainder Instead of Long Division

This teaches replacing a polynomial by its remainder modulo a linear expression.

Problem. Find all possible values of gcd⁡(n+5,n2+3n+9) \gcd(n+5,n^2+3n+9) for positive integers nn.

Solution.

Let d=gcd⁡(n+5,n2+3n+9)d=\gcd(n+5,n^2+3n+9). Since n≡−5(modn+5)n\equiv -5 \pmod{n+5}, we get n2+3n+9≡25−15+9=19(modn+5)n^2+3n+9\equiv 25-15+9=19\pmod{n+5}. Hence d=gcd⁡(n+5,19)d=\gcd(n+5,19). Only 11 and 1919 are possible. Both occur: if n+5n+5 is not divisible by 1919, the gcd is 11, while n=14n=14 gives 1919.

Comment. A linear factor turns the polynomial into a constant remainder.

Example 2. GCD with a Neighbouring Linear Factor

This shows how to prove that a common divisor is bounded by a small number.

Problem. Prove that gcd⁡(n2+n+1,n−1) \gcd(n^2+n+1,n-1) divides 33.

Solution.

If d∣n−1d\mid n-1, then n≡1(modd)n\equiv1\pmod d. Therefore n2+n+1≡1+1+1=3(modd)n^2+n+1\equiv 1+1+1=3\pmod d. Hence, if dd also divides n2+n+1n^2+n+1, then d∣3d\mid3. Thus gcd⁡(n2+n+1,n−1)∣3 \gcd(n^2+n+1,n-1)\mid3.

Comment. We do not always need the exact gcd; often it is enough to restrict it.

Example 3. GCD of Numbers am−1a^m-1

A standard olympiad template: the Euclidean algorithm moves to the exponents.

Problem. Prove that gcd⁡(2m−1,2n−1)=2gcd⁡(m,n)−1 \gcd(2^m-1,2^n-1)=2^{\gcd(m,n)}-1 .

Solution.

Let g=gcd⁡(m,n)g=\gcd(m,n). The number 2g−12^g-1 divides both expressions because g∣mg\mid m and g∣ng\mid n. Conversely, suppose m>nm>n. Then 2m−1−(2m−n)(2n−1)=2m−n−12^m-1-(2^{m-n})(2^n-1)=2^{m-n}-1. Thus any common divisor of 2m−12^m-1 and 2n−12^n-1 also divides 2m−n−12^{m-n}-1. Repeating the Euclidean algorithm on the exponents leads to 2g−12^g-1.

Comment. The Euclidean algorithm is applied to the exponents, not to the huge numbers themselves.

Example 4. Common Divisors and Coprimality

This teaches excluding a prime divisor by contradiction with gcd⁡(a,b)=1 \gcd(a,b)=1 .

Problem. Let gcd⁡(a,b)=1 \gcd(a,b)=1 . Prove that gcd⁡(a+b,a2+b2) \gcd(a+b,a^2+b^2) divides 22.

Solution.

Let a prime pp divide both a+ba+b and a2+b2a^2+b^2. From a+b≡0(modp)a+b\equiv0\pmod p we get b≡−a(modp)b\equiv -a\pmod p. Then a2+b2≡2a2(modp)a^2+b^2\equiv2a^2\pmod p. If p≠2p\ne2, then p∣ap\mid a, hence p∣bp\mid b, impossible. Therefore the only possible prime divisor is 22, so the whole gcd divides 22.

Comment. Factoring is unnecessary; it is enough to study a prime divisor.

Example 5. A Common Divisor Becomes a Congruence

This shows how a condition gcd⁡>1 \gcd>1 turns into a congruence.

Problem. Find all positive integers nn such that gcd⁡(n2+2,n3+3)>1 \gcd(n^2+2,n^3+3)>1 .

Solution.

Let dd be a common divisor. Then d∣n(n2+2)−(n3+3)=2n−3d\mid n(n^2+2)-(n^3+3)=2n-3. Multiply the first expression by 44: 4(n2+2)=4n2+84(n^2+2)=4n^2+8. From 2n≡3(modd)2n\equiv3\pmod d, we get 4n2≡9(modd)4n^2\equiv9\pmod d, so d∣17d\mid17. Thus only the common prime divisor 1717 is possible. It appears exactly when 2n≡3(mod17)2n\equiv3\pmod{17}, that is, n≡10(mod17)n\equiv10\pmod{17}. Answer: n≡10(mod17)n\equiv10\pmod{17}.

Comment. First the common divisor is severely restricted, then attainability is checked.

Example 6. Powers with Two Bases

This prepares for problems where one has to introduce an inverse element.

Problem. Let a>b>0a>b>0 and gcd⁡(a,b)=1 \gcd(a,b)=1 . Prove that gcd⁡(am−bm,an−bn)=agcd⁡(m,n)−bgcd⁡(m,n) \gcd(a^m-b^m,a^n-b^n)=a^{\gcd(m,n)}-b^{\gcd(m,n)} .

Solution.

Let g=gcd⁡(m,n)g=\gcd(m,n). The right-hand side divides both expressions. Conversely, let dd be a common divisor. Since gcd⁡(b,d)=1 \gcd(b,d)=1 , bb is invertible modulo dd. From am≡bma^m\equiv b^m and an≡bna^n\equiv b^n, we obtain (ab−1)m≡1(ab^{-1})^m\equiv1 and (ab−1)n≡1(modd)(ab^{-1})^n\equiv1\pmod d. Hence (ab−1)g≡1(modd)(ab^{-1})^g\equiv1\pmod d, so ag≡bg(modd)a^g\equiv b^g\pmod d, and d∣ag−bgd\mid a^g-b^g.

Comment. The hidden step is that division by bb is allowed only after coprimality is checked.

Example 7. GCD of Neighbouring Factorials

This shows how a linear combination gives a small number.

Problem. Prove that gcd⁡(n!+1,(n+1)!+1)=1 \gcd(n!+1,(n+1)!+1)=1 .

Solution.

Let dd divide both numbers. Then d∣(n+1)!+1−(n+1)(n!+1)=−nd\mid (n+1)!+1-(n+1)(n!+1)=-n. Hence d∣nd\mid n. But d∣n!+1d\mid n!+1 and d∣nd\mid n imply d∣n!d\mid n!, so d∣1d\mid1. Therefore d=1d=1.

Comment. The combination is chosen to eliminate the factorial.

Example 8. A Strong Prime-Divisor Argument

An olympiad-style example: instead of computing the gcd, we analyse a possible prime divisor.

Problem. Let gcd⁡(a,b)=1 \gcd(a,b)=1 . Find gcd⁡(a2+b2,a3+b3) \gcd(a^2+b^2,a^3+b^3) .

Solution.

Consider an odd prime pp dividing both numbers. Since p∤bp\nmid b, put t≡ab−1(modp)t\equiv ab^{-1}\pmod p. Then t2≡−1t^2\equiv-1 and t3≡−1(modp)t^3\equiv-1\pmod p. Dividing the second congruence by the first gives t≡1(modp)t\equiv1\pmod p, but then 1≡−1(modp)1\equiv-1\pmod p, impossible for odd pp. Thus there are no odd prime divisors. Now check 22: if a,ba,b are both odd, both expressions are even and a2+b2≡2(mod4)a^2+b^2\equiv2\pmod4, so the gcd is 22. If one of a,ba,b is even, both expressions are odd, so the gcd is 11.

Comment. This trains prime-divisor analysis and modular inverses.

Worked examples

No worked examples were provided.

Practise this topic