Professional Documents
Culture Documents
Euclidean Algorithm
ft. Remainder Bounding
Evan Chen《陳誼廷》
1 October 2023
》
DNY-EUCLID
廷
誼 se
陳 U
n《 al
h e rn
C nt e
n
a , I
Ev I S
y
B O T
OTIS, © Evan Chen, internal use only. Artwork contributed by Alex Zhao.
1
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
§1 Lecture Notes
§1.1 Euclidean Algorithm
The main idea here is that if a and b are positive integers with greatest common divisor
d, then any linear combination of a and b is still divisible by d. Bezout’s Theorem says
this is “best possible”:
Theorem (Bezout)
If a1 , . . . , an are integers with gcd(a1 , . . . , an ) = d then there exists integers c1 , . . . ,
cn such that X
ci ai = d.
》
A consequence of this is the so-called Euclidean algorithm: one can compute gcd(A, B)
廷
by iteratively doing gcd(A, B) = gcd(A, B − A), et cetera. (This often works well if A
and B are polynomials, or if |A − B| is “small”.)
誼 se
Example 1.1
陳 U
For positive integers a, b and x > 1 show that gcd(xa − 1, xb − 1) = xgcd(a,b) − 1.
《 al
Walkthrough. νp can work, but it’s more economical to:
n
e rn
(a) Show that gcd(xa − 1, xb − 1) = gcd(xa−b − 1, xb − 1) when a > b.
h
(b) Iterate to conclude.
C nt e
n
a , I
Example 1.2 (JMO 2017/2)
v
Show that the Diophantine equation
E I S
3x3 + xy 2 x2 y + 3y 3 = (x − y)7
y T
has infinitely many solutions in positive integers, and characterize all the solutions.
17JMO2
B O
Walkthrough. Let x = da, y = db, where gcd(a, b) = 1 and a > b.
(a − b)7 | P (a, b)
(b) By considering ν2 ’s, show that a and b are not both odd. Since gcd(a, b) = 1, this
implies one is even and the other is odd.
(c) Show that each of the four factors of P (a, b) shares no common factors with a − b,
for any pair (a, b) of relatively prime integers. This will require you to use (b).
2
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
n m
is an integer for all pairs of integers n ≥ m ≥ 1.
00PTNMB2 Walkthrough. It should be possible to brute-force the problem with νp ’s, but this
problem has an unusually slick solution if you think of gcd(m, n) as linear combinations
of m and n.
(a) Show that nn m
n
∈ Z. (Yes, this is trivial.)
》
(c) Conclude!
廷
Observe that the problem is actually equivalent to (b) given the vacuous (a).
誼 se
§1.2 Remainder Bounding
陳 U
A particularly nice case is when A | B. In such a situation, one can do the following:
《 al
• Add or subtract multiples of the expression A from B; equivalently, taking B
n
(mod A).
h e rn
• Factor the expression B, if you know something about its prime factors.
C e
• If |B| < |A|, deduce B = 0.
n nt
For lack of a better name, I privately call this technique “remainder bounding”.
I
a ,
Some special cases: if A and B are polynomials one can often do polynomial long
v
division in this way. Also, if there is some “free choice” in the problem one can often also
E S
e.g. cause A to be 0 modulo a large prime p; if p > B this would also let one conclude
I
B = 0.
y
B O T
Example 1.4 (USAMO 2017/1)
Prove that there exist infinitely many pairs of relatively prime positive integers
a, b > 1 for which a + b divides ab + ba .
17AMO1 Walkthrough. It’s relatively easy to half-heartedly guess a curve of solutions (a, b)
that work. However, in this walkthrough, for demonstration I’m actually going to solve
the following problem instead:
Characterize all integers a > b > 0 such that a is even, gcd(a, b) = 1, and
a + b divides ab + ba .
Thus, you might see why I was surprised when someone told me about (a, b) = (2n +
1, 2n − 1) solving the original unmodified problem! My first reflex had been to simply
find all solutions, by remainder bounding:
(a) Show that a + b | ab + ba ⇐⇒ ba−b ≡ 1 (mod a + b) (assuming that a is even and
b is odd).
(b) Let d = a − b now, so (a) reads bd ≡ 1 (mod d + 2b). Repeat the same trick to end
up with an expression of the form d + 2b | f (d) for some function f .
3
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
Thus this is essentially a full characterization; for any d, we look at f (d), and any factor
exceeding d with the same parity will yield a solution to the original. Of course, this
implies the original USAMO problem:
(c) When d ≡ 1 (mod 4) and d > 1, extract a pair (a, b) that works.
This might seem like a roundabout way of solving a very easy problem, but I think it’s
justified on the basis that I did not need to make many arbitrary decisions. I really only
assumed a was even and b was odd for simplicity with dealing with the (−1)b ’s and so
on, and it’s not hard to imagine this can work in other cases too.
In other words: it seems in principle we should be able to get a good handle on all
solutions.
》
Example 1.5 (Shortlist 2016 N4)
Find all quadruples (n, m, k, `) of positive integers such that n > 1 and nk + mn` + 1
廷
divides nk+` − 1.
誼 se
16SLN4 Walkthrough. This problem is the crown example of the remainder bounding technique.
Give this one your best shot. It may be helpful to read through the example application
陳 U
to USAMO 2017/1 before tackling this one.
In what follows, A denotes the left-hand side nk + mn` + 1.
n《 al
(a) Add a suitable multiple of A to eliminate the −1 from the right-hand side.
e rn
At this point one should obtain multiples of n on the right-hand side. We want to factor
h
out these n’s, but it depends on whether ` ≤ k or not.
C t e
Suppose first ` ≤ k.
n I n
(b) Prove that the situation is equivalent to
va , A | nk−` + m − mn` − 1.
E I S
(c) Show that the right-hand side of (b) has absolute value less than A.
y
B O T
(d) Determine the value of m and show that ` | k. This gives you one curve of solutions.
A | n` + mn`−k + 1.
(g) Suppose m = 1. Prove that ` = 2k. This gives you the second curve of solutions.
04SLN3 Walkthrough. This is about as standard as a divisibility functional equation will get.
Starting off:
4
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
Now, our idea is to first try to find certain values for which it’s easy to describe f . A
good choice for this is to think about making the right-hand side (m2 + n)2 the square
of a prime, so that there are only three possibilities. You should get the following result:
(b) For each prime p, show that f (p − 1) ∈ {p − 1, p2 − 1} with one suitable substitution.
Now we have arbitrarily large known values, so it should be straightforward to use a size
argument.
》
In some situations, starting from A | B, you actually want to first pick a nice c > 0
(which could be either a constant or some expression, etc.) and work with A | cB instead.
廷
This is a bit ironic because it seems to go the “other way”, but there are situations in
which this actually makes taking mod A easier.
誼 se
As a really simple example, if you are starting from 2x + y | x2 + 2y (I made that up),
陳 U
you might actually prefer to work with 2x + y | 2x2 + 2y+1 instead because now you can
destroy the 2x2 term by subtracting x(2x + y), which you couldn’t do before without the
《 al
coefficient of 2. Some more substantial examples appear in the practice problems.
n
e rn
§1.3 Dirichlet
h e
Theorem 1.7 (Dirichlet’s theorem on arithmetic progressions)
C t
If gcd(a, b) = 1 and a, b > 0, then there are infinitely many primes in {an + b}∞
n=1 .
n
a , I n
Ev I S
y
B O T
5
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
§2 Practice Problems
Instructions: Solve [40♣]. If you have time, solve [50♣]. Problems with red weights are mandatory.
》
any prime, and
ab + 3b + 8
n= 2 .
廷
a +b+3
98IMO4
[2♣] Problem 2 (IMO 1998/4). Determine all pairs (x, y) of positive integers such that
誼 se
x2 y + x + y is divisible by xy 2 + y + 7.
17HMMTA4
陳 U
[2♣] Problem 3 (HMMT 2017 A4). Find all pairs of positive integers (a, b) for which
ab divides a2017 + b.
《 al
13APMO2
[2♣] Problem 4 (APMO 2013, added by Samuel Zhou). Determine all positive integers
n
e rn
n for which
n2 + 1
h
√ 2
e
b nc + 2
C t
is an integer.
n n
05SLN6
I
[5♣] Required Problem 5 (Shortlist 2005 N6). Let a and b be positive integers. If
va ,
an + n divides bn + n for every positive integer n, prove that a = b.
S
22APMO1
E I
[3♣] Problem 6 (APMO 2022/1, added by Lum Jerliu). Find all pairs (a, b) of positive
integers such that b2 | a3 and a − 1 | b − 1.
y T
13ESLN4
B O
[3♣] Problem 7 (ELMO SL 2013 N4). Find all triples of positive integers (a, b, c) such
that the following property holds: if n is a positive integer not divisible by any prime
less than 2013 then an + bn + n is divisible by n + c.
02IMO3
[9♣] Problem 8 (IMO 2002/3). Find all pairs of positive integers m, n ≥ 3 for which
there exist infinitely many positive integers a such that
am + a − 1
an + a2 − 1
is itself an integer.
§2.2 FE
11SLN3
[5♣] Required Problem 9 (Shortlist 2011). Let n ≥ 1 be an odd integer. Determine
all functions f : Z → Z such that f (x) − f (y) divides xn − y n for all distinct integers x
and y.
13SLN1
[2♣] Problem 10 (Shortlist 2013). Find all functions f : Z>0 → Z>0 such that
m2 + f (n) | mf (m) + n.
6
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
16SLN6
[5♣] Required Problem 11 (Shortlist 2016). Find all functions f : Z>0 → Z>0 such that
for all positive integers m and n, f (m)+f (n)−mn is nonzero and divides mf (m)+nf (n).
19SLN4
[3♣] Problem 12 (Shortlist 2019). Find all functions f : Z>0 → Z>0 such that a + f (b)
divides a2 + bf (a) for all positive integers a and b with a + b > 2019.
11IMO5
[3♣] Problem 13 (IMO 2011). Let f : Z → Z>0 be a function such that f (m − n) |
f (m) − f (n) for m, n ∈ Z. Prove that if m, n ∈ Z satisfy f (m) ≤ f (n) then f (m) | f (n).
§2.3 Mix
17ELMO1
[2♣] Problem 14 (ELMO 2017/1). Let a1 , a2 , . . . , an be positive integers with product
P , where n is an odd positive integer. Prove that
》
gcd(an1 + P, an2 + P, . . . , ann + P ) ≤ 2 gcd(a1 , . . . , an )n .
廷
11IMO1
[2♣] Problem 15 (IMO 2011/1). Given any set A = {a1 , a2 , a3 , a4 } of four distinct
positive integers, we denote the sum a1 + a2 + a3 + a4 by sA . Let nA denote the number
誼 se
of pairs (i, j) with 1 ≤ i < j ≤ 4 for which ai + aj divides sA . Find all sets A of four
陳 U
distinct positive integers which achieve the largest possible value of nA .
ZAB34B8B
[2♣] Problem 16 (APMO Divis). Are there distinct prime numbers a, b, c which satisfy
《 al
a | bc + b + c, b | ca + c + a, c | ab + a + b?
n
20TSTST4
e rn
[5♣] Problem 17 (TSTST 2020/4). Find all pairs of positive integers (a, b) satisfying
h
the following conditions:
C t e
(i) a divides b4 + 1,
n I n
(ii) b divides a4 + 1,
va ,
√ √
(iii) b ac = b bc.
E S
16IMO4
I
[3♣] Problem 18 (IMO 2016). A set of positive integers is called fragrant if it contains
y T
at least two elements and each of its elements has a prime factor in common with at least
one of the other elements. Let P (n) = n2 + n + 1. What is the smallest possible positive
B O
integer value of b such that there exists a non-negative integer a for which the set
is fragrant?
01AMO5
[3♣] Problem 19 (USAMO 2001). Let S ⊆ Z be such that:
(a) there exist a, b ∈ S with gcd(a, b) = gcd(a − 2, b − 2) = 1;
7
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
(a) ai ∈ S for i = 1, . . . , n.
Prove that S = Z.
14SLN5
[5♣] Problem 22 (Shortlist 2014 N5). Find all primes p and positive integers (x, y)
such that xp−1 + y and y p−1 + x are powers of p.
21HMMTT6
[5♣] Required Problem 23 (HMMT 2021 T6). Find all positive integers n for which
the following holds: if d > 0 divides n, then d2 + d + 1 divides n2 + n + 1.
[1♣] Mini Survey. Fill out feedback on the OTIS-WEB portal when submitting this
》
problem set. Any thoughts on problems (e.g. especially nice, instructive, easy, etc.) or
overall comments on the unit are welcome.
廷
In addition, if you have any suggestions for problems to add, or want to write hints for
one problem you really liked, please do so in the ARCH system!
誼 se
The maximum number of [♣] for this unit is [81♣], including the mini-survey.
陳 U
n《 al
h e rn
C nt e
n
a , I
Ev I S
y
B O T
8
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
》
gcd(a − b, a2 + 3b2 ) = gcd(a − b, 4b2 ) = 1
廷
and similarly gcd(a − b, 3a2 + b2 ) = 1. Thus a − b is coprime to each of a, b, a2 + 3b2 ,
3a2 + b2 and this forces a − b = 1.
誼 se
Of course (?) holds whenever a − b = 1 as well, and thus (?) ⇐⇒ a − b = 1. This
陳 U
describes all solutions.
Remark. For cosmetic reasons, one can reconstruct the curve explicitly by selecting b =
《 al
2 (n − 1), a = 2 (n + 1) with n > 1 an odd integer. Then d = ab(a + 3b )(3a + b ) =
1 1 2 2 2 2
n
(n−1)(n+1)(n2 +n+1)(n2 −n+1)
4 , and hence the solution is
n6 −1
e rn
4 =
h
(n + 1)(n6 − 1) (n − 1)(n6 − 1)
C e
(x, y) = (da, db) = , .
8 8
n nt
The smallest solutions are (364, 182), (11718, 7812), . . . .
va , I
E S
§3.2 Solution 1.3, Putnam 2000 B2
y T I
It should be possible to brute-force the problem with νp ’s, but here is a slick solution:
note that
B O
n n m n n−1
∈ Z, = ∈Z
n m n m m−1
(indeed the problem statement implies these). Hence any linear combination of this is an
integer, and we are done by Bezout lemma.
x+d x−d
a= , b= .
2 2
To see this works, first check that b is odd and a is even. Let d = a − b be odd. Then:
a + b | ab + ba ⇐⇒ (−b)b + ba ≡ 0 (mod a + b)
a−b
⇐⇒ b ≡1 (mod a + b)
d
⇐⇒ b ≡ 1 (mod d + 2b)
⇐⇒ (−2) ≡ dd d
(mod d + 2b)
9
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
⇐⇒ d + 2b | dd + 2d .
So it would be enough that
dd + 2d dd + 2d
1
d + 2b = =⇒ b = −d
d+2 2 d+2
which is what we constructed. Also, since gcd(x, d) = 1 it follows gcd(a, b) = gcd(d, b) =
1.
Remark. Ryan Kim points out that in fact, (a, b) = (2n − 1, 2n + 1) is always a solution.
》
We claim that all quadruples are given by:
廷
• m = 1 and ` = 2k, or
• ` | k and m = .
誼 se
nk−` −1
n` −1
Clearly they work.
陳 U
Rewrite as:
nk + mn` + 1 | nk+` + nk + mn` .
《 al
Now we split into cases (inevitable given the answer form):
n
e rn
• If ` ≤ k, then we factor out n` to get
h e
nk + mn` + 1 | nk + nk−` + m
C t
=⇒ nk + mn` + 1 | nk−` + m − mn` − 1.
n
a , I n
In the last, since max(nk−` + m, mn` + 1) < nk + mn` + 1, it follows the right-hand
v
side must be zero. Consequently, m = nn` −1 . In order for this to be an integer,
k−` −1
E S
we must have ` | k − `, or ` | k.
y T I
• Now suppose ` > k. We get
B O
nk + mn` + 1 | n` + mn`−k + 1.
Now we divide into two sub-cases:
– If m = 1, then subtracting once more gives
nk + mn` + 1 | n`−k − nk .
Since the right-hand side is clearly less than the left in absolute value, it
follows ` − k = k, or ` = 2k.
– If m ≥ 2, then we contend that nk + mn` + 1 > n` + mn`−k + 1 > 0 which
would be a contradiction. It would suffice to check (m − 1)n` + nk > mn`−k ,
but n` ≥ 2n`−k (since n > 1) and (m − 1)n` > (m − 1)n`−k , hence done.
This completes all three cases, as desired.
10
Evan Chen《陳誼廷》 (OTIS, updated 2023-10-01) Euclidean Algorithm
1 + f (p − 1) | p2
2
f (p − 1)2 + 1 | (p − 1)2 + 1 .
》
廷
誼 se
陳 U
n《 al
h e rn
C nt e
n
a , I
Ev I S
y
B O T
11