Chapter

Advanced GCD Problems

This module teaches how to turn gcd problems into remainders, linear combinations, prime-divisor conditions, and the Euclidean algorithm on exponents.
Log in to track solved progress and bookmarks.

Theory

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 \bmod a) \), and the fact that if \(d\) divides two numbers, then \(d\) divides every integer linear combination of them. If \( \gcd(a,b)=1 \) and \(a\mid bc\), then \(a\mid c\). For powers, the key identity is \( \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 \), powers \(a^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+c\), replace \(n\) by \(-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\mid ab\) that \(d\mid a\) or \(d\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?

Examples

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,n^2+3n+9) \) for positive integers \(n\).

Solution.

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

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(n^2+n+1,n-1) \) divides \(3\).

Solution.

If \(d\mid n-1\), then \(n\equiv1\pmod d\). Therefore \(n^2+n+1\equiv 1+1+1=3\pmod d\). Hence, if \(d\) also divides \(n^2+n+1\), then \(d\mid3\). Thus \( \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 \(a^m-1\)

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

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

Solution.

Let \(g=\gcd(m,n)\). The number \(2^g-1\) divides both expressions because \(g\mid m\) and \(g\mid n\). Conversely, suppose \(m>n\). Then \(2^m-1-(2^{m-n})(2^n-1)=2^{m-n}-1\). Thus any common divisor of \(2^m-1\) and \(2^n-1\) also divides \(2^{m-n}-1\). Repeating the Euclidean algorithm on the exponents leads to \(2^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 \).

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

Solution.

Let a prime \(p\) divide both \(a+b\) and \(a^2+b^2\). From \(a+b\equiv0\pmod p\) we get \(b\equiv -a\pmod p\). Then \(a^2+b^2\equiv2a^2\pmod p\). If \(p\ne2\), then \(p\mid a\), hence \(p\mid b\), impossible. Therefore the only possible prime divisor is \(2\), so the whole gcd divides \(2\).

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 \) turns into a congruence.

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

Solution.

Let \(d\) be a common divisor. Then \(d\mid n(n^2+2)-(n^3+3)=2n-3\). Multiply the first expression by \(4\): \(4(n^2+2)=4n^2+8\). From \(2n\equiv3\pmod d\), we get \(4n^2\equiv9\pmod d\), so \(d\mid17\). Thus only the common prime divisor \(17\) is possible. It appears exactly when \(2n\equiv3\pmod{17}\), that is, \(n\equiv10\pmod{17}\). Answer: \(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>0\) and \( \gcd(a,b)=1 \). Prove that \( \gcd(a^m-b^m,a^n-b^n)=a^{\gcd(m,n)}-b^{\gcd(m,n)} \).

Solution.

Let \(g=\gcd(m,n)\). The right-hand side divides both expressions. Conversely, let \(d\) be a common divisor. Since \( \gcd(b,d)=1 \), \(b\) is invertible modulo \(d\). From \(a^m\equiv b^m\) and \(a^n\equiv b^n\), we obtain \((ab^{-1})^m\equiv1\) and \((ab^{-1})^n\equiv1\pmod d\). Hence \((ab^{-1})^g\equiv1\pmod d\), so \(a^g\equiv b^g\pmod d\), and \(d\mid a^g-b^g\).

Comment. The hidden step is that division by \(b\) 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 \).

Solution.

Let \(d\) divide both numbers. Then \(d\mid (n+1)!+1-(n+1)(n!+1)=-n\). Hence \(d\mid n\). But \(d\mid n!+1\) and \(d\mid n\) imply \(d\mid n!\), so \(d\mid1\). Therefore \(d=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 \). Find \( \gcd(a^2+b^2,a^3+b^3) \).

Solution.

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

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

Problems

Problems

#1.1
#1.1

Constant Remainder

Euclidean Algorithm Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find all possible values of \( \gcd(n+4,n^2+2n+10) \), where \(n\) is a positive integer.

Details
Problem: NT-B2-M01-P001
Difficulty: Level 2 of 5
Tag: Euclidean Algorithm
Grade: Grade 8, Grade 9, Grade 10
#1.2
#1.2

Always Coprime

Divisibility Grade 8 Grade 9 Grade 10 ★★☆☆☆

Prove that for every positive integer \(n\), the numbers \(n^2+n+1\) and \(n+1\) are coprime.

Details
Problem: NT-B2-M01-P002
Difficulty: Level 2 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#1.3
#1.3

A Linear Combination

Euclidean Algorithm Grade 8 Grade 9 Grade 10 ★★☆☆☆

Prove that \(3n+2\) and \(5n+3\) are coprime for every integer \(n\).

Details
Problem: NT-B2-M01-P003
Difficulty: Level 2 of 5
Tag: Euclidean Algorithm
Grade: Grade 8, Grade 9, Grade 10
#1.4
#1.4

When the GCD Is Greater Than One

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★☆☆☆

Find all positive integers \(n\) such that \( \gcd(n^2+1,n+3)>1 \).

Details
Problem: NT-B2-M01-P004
Difficulty: Level 2 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10
#1.5
#1.5

A Square and an Odd Divisor

Divisibility Grade 8 Grade 9 Grade 10 ★★☆☆☆

Prove that \( \gcd(2n+1,4n^2+4n+3)=1 \) for every integer \(n\).

Details
Problem: NT-B2-M01-P005
Difficulty: Level 2 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#1.6
#1.6

GCD of Differences of Powers

Divisibility Grade 8 Grade 9 Grade 10 ★★★☆☆

Prove that for \(n>1\), \( \gcd(n^3-1,n^2-1)=n-1 \).

Details
Problem: NT-B2-M01-P006
Difficulty: Level 3 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#1.7
#1.7

A Small Common Divisor

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★★☆☆

Find all positive integers \(n\) such that \( \gcd(n^2+n+1,2n+1)>1 \).

Details
Problem: NT-B2-M01-P007
Difficulty: Level 3 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10
#1.8
#1.8

Sum and Sum of Squares

Divisibility Grade 8 Grade 9 Grade 10 ★★★☆☆

Let \( \gcd(a,b)=1 \). Prove that \( \gcd(a+b,a^2+b^2) \) is \(1\) or \(2\). State when it equals \(2\).

Details
Problem: NT-B2-M01-P008
Difficulty: Level 3 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#1.9
#1.9

Coprime Polynomials

Euclidean Algorithm Grade 8 Grade 9 Grade 10 ★★★☆☆

Prove that \( \gcd(n^2+3n+3,n^2+5n+7)=1 \) for every integer \(n\).

Details
Problem: NT-B2-M01-P009
Difficulty: Level 3 of 5
Tag: Euclidean Algorithm
Grade: Grade 8, Grade 9, Grade 10
#1.10
#1.10

Coprime Exponents

Powers Grade 8 Grade 9 Grade 10 ★★★☆☆

Let \(a>1\), and let \(m,n\) be positive integers with \( \gcd(m,n)=1 \). Prove that \( \gcd(a^m-1,a^n-1)=a-1 \).

Details
Problem: NT-B2-M01-P010
Difficulty: Level 3 of 5
Tag: Powers
Grade: Grade 8, Grade 9, Grade 10
#1.11
#1.11

Neighbouring Powers

Powers Grade 8 Grade 9 Grade 10 ★★★☆☆

Prove that \( \gcd(3^n-1,3^n+2)=1 \) for every positive integer \(n\).

Details
Problem: NT-B2-M01-P011
Difficulty: Level 3 of 5
Tag: Powers
Grade: Grade 8, Grade 9, Grade 10
#1.12
#1.12

The Seventeenth Remainder

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★★★☆

Find all positive integers \(n\) such that \( \gcd(n^2+2,n^3+3)>1 \).

Details
Problem: NT-B2-M01-P012
Difficulty: Level 4 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10
#1.13
#1.13

Neighbouring Factorials

Factorials Grade 8 Grade 9 Grade 10 ★★★★☆

Prove that \( \gcd(n!+1,(n+1)!+1)=1 \) for every positive integer \(n\).

Details
Problem: NT-B2-M01-P013
Difficulty: Level 4 of 5
Tag: Factorials
Grade: Grade 8, Grade 9, Grade 10
#1.14
#1.14

A Cubic Restriction

Divisibility Grade 8 Grade 9 Grade 10 ★★★★☆

Find all primes \(p\) such that \( \gcd(p^2+1,p^3+1)>1 \).

Details
Problem: NT-B2-M01-P014
Difficulty: Level 4 of 5
Tag: Divisibility
Grade: Grade 8, Grade 9, Grade 10
#1.15
#1.15

Two Bases

Powers Grade 8 Grade 9 Grade 10 ★★★★☆

Let \(a>b>0\), \( \gcd(a,b)=1 \). Prove that \( \gcd(a^m-b^m,a^n-b^n)=a^{\gcd(m,n)}-b^{\gcd(m,n)} \).

Details
Problem: NT-B2-M01-P015
Difficulty: Level 4 of 5
Tag: Powers
Grade: Grade 8, Grade 9, Grade 10
#1.16
#1.16

Mixed Exponents

Powers Grade 8 Grade 9 Grade 10 ★★★★☆

Find \( \gcd(4^m-1,2^n-1) \) in terms of \(m\) and \(n\).

Details
Problem: NT-B2-M01-P016
Difficulty: Level 4 of 5
Tag: Powers
Grade: Grade 8, Grade 9, Grade 10
#1.17
#1.17

Even Powers and a Sum

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★★★★

Let \( \gcd(x,y)=1 \). Find \( \gcd(x+y,x^{2k}+y^{2k}) \), where \(k\) is a positive integer.

Details
Problem: NT-B2-M01-P017
Difficulty: Level 5 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10
#1.18
#1.18

A Square and a Cube

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★★★★

Let \( \gcd(a,b)=1 \). Find \( \gcd(a^2+b^2,a^3+b^3) \).

Details
Problem: NT-B2-M01-P018
Difficulty: Level 5 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10
#1.19
#1.19

Neighbouring Terms of a Sequence

Sequences Grade 8 Grade 9 Grade 10 ★★★★★

A sequence is defined by \(u_1=2\), \(u_{n+1}=u_n^2-u_n+1\). Prove that any two distinct terms of the sequence are coprime.

Details
Problem: NT-B2-M01-P019
Difficulty: Level 5 of 5
Tag: Sequences
Grade: Grade 8, Grade 9, Grade 10
#1.20
#1.20

A Quadratic Form and Powers

Modular Arithmetic Grade 8 Grade 9 Grade 10 ★★★★★

Let \( \gcd(a,b)=1 \), and let \(n\) be a positive integer. Find \( \gcd(a^2+ab+b^2,a^n-b^n) \).

Details
Problem: NT-B2-M01-P020
Difficulty: Level 5 of 5
Tag: Modular Arithmetic
Grade: Grade 8, Grade 9, Grade 10

Ladders

No published ladders were found.
Next Chapter