We will proceed by steps.
- First Step: We prove it for n=p a prime number, with p≥7:
If p divides k then a=b=1 satisfy the condition. If p does not divide k then let us consider two cases:
a. If k is a quadratic residue modulo p, and c and c+1 are two consecutive quadratic residues modulo p such that 1≤c<c+1≤p−1, then both kc and kc+k are quadratic residues relatively prime with p. This means that there exist a and b, each relatively prime with p, such that a2≡ck and b2≡ck+k modulo p and therefore a2−b2+k≡0(modp).
b. If k is a quadratic nonresidue modulo p, and c and c+1 are two consecutive quadratic nonresidues modulo p such that 1≤c<c+1≤p−1, then both kc and kc+k are quadratic residues relatively prime with p. This means that there exist a and b, each relatively prime with p, such that a2≡ck and b2≡ck+k modulo p and therefore a2−b2+k≡0(modp).
Thus, this first step reduces to proving that among 1,2,…,p−1 there are two consecutive quadratic residues and two consecutive quadratic nonresidues modulo p. We will prove this fact in two different ways:
First way. Notice that both 1 and 4 are quadratic residues.
If 2 or 3 is a quadratic residue then there exists at least two consecutive quadratic residues among 1,2,3,4. But exactly half of the numbers 1,2,…,p−1 are quadratic nonresidues. So there exist at least 2p−3 quadratic nonresidues among the p−5 consecutive numbers 5,6,…,p−1. So, by a pigeonhole principle, at least two of them must be consecutive.
If 2 and 3 are consecutive quadratic nonresidues, we have two possibilities: Either −1 is a quadratic nonresidue and in this case p−3 and p−2 are consecutive quadratic residues, or −1 is a quadratic residue, which means that p≡1(mod4), p≥13, and for each integer m the integers m and p−m are either both quadratic residues or both quadratic nonresidues. This means that there are 4p−1 quadratic residues between 1,2,…,2p−1.
If 2p−1 is a quadratic residue then 2p−1,2p+1 are two consecutive quadratic residues.
If 2p−1 is a quadratic nonresidue then there are 4p−5 quadratic residues among the 2p−9 consecutive numbers 4,5,…,2p−3. But 2p−9 is an even number. So, by a pigeonhole principle, at least two of the quadratic residues must be consecutive.
Second way. In this second way we will compute the exact number of consecutive pairs of quadratic residues and the exact number of consecutive pairs of quadratic nonresidues.
Consider the partition
{1,2,…,p−1}=Q1∪N1∪Q2∪N2∪⋯∪Qk∪Nk
where Q1 is the set of all the first consecutive quadratic residues, possibly reduced to the singleton {1} when 2 is a quadratic nonresidue, N1 is the set of all the first consecutive quadratic nonresidues, possibly reduced to a singleton, Q2 is the set of all the first consecutive quadratic residues after the elements of N1, and so on... Notice that Nk is the only possibly empty set when p−1 is a quadratic residue.
Let a∈{1,2,…,p−2}. Notice that (pa)(pa+1)=1 if and only if a,a+1 are both quadratic residues or both quadratic nonresidues, where (pa) is the Legendre symbol. This means that (pa)(pa+1)=−1 if and only if a,a+1 do not belong to the same subset of the partition. This means that there are either 2k−2 or 2k−1 pairs (a,a+1), with 1≤a≤p−2 such that (pa)(pa+1)=−1, depending on whether Nk is empty or not. But (pa)(pa+1)=(pa)2(p1+a−1)=(p1+a−1). But when a covers all the residues 1,2,…,p−2, its inverse a−1 covers all the residues 1,2,…,p−2. Because there are exactly 2p−1 quadratic nonresidues among the residues 2,3,…,p−1, we deduce that k=4p+3 if p≡1(mod4) and k=4p+1 if p≡3(mod4).
Now, for 1≤i≤k, there are CardQi−1 consecutive pairs of quadratic residues in Qi and CardNi−1 consecutive pairs of quadratic nonresidues in Ni. We deduce that the total number of consecutive pairs of quadratic residues in {1,2,…,p−1} is
i=1∑k(CardQi−1)=Cardi=1⋃kQi−k=2p−1−k=⌊4p−3⌋≥1,
and the total number of consecutive pairs of quadratic nonresidues in {1,2,…,p−1} is
∑i=1k−1(CardNi−1)=Card⋃i=1k−1Ni−k+1=2p−1−k+1=⌊4p−1⌋≥1, if p≡1(mod4) and
i=1∑k(CardNi−1)=Cardi=1⋃kNi−k=2p−1−k=⌊4p−1⌋≥1,
if p≡3(mod4).
- Second Step: We prove it for n=pα, with p≥7 is a prime number and α≥1. We proceed by induction on α:
For α=1, we have already proved in the first step that there exist two integers a1,b1, each relatively prime with p, such that p divides a12−b12+k.
For α≥1, assume that there exists an integer aα≡a1(modp) such that pα divides aα2−b12+k. Consider the polynomial P(X)=X2−b12+k. Because P(aα)≡0(modpα) and P′(aα)=2aα≡2a1≡0(modp), there exists, from Hensel's lemma, an integer aα+1≡aα(modpα), and therefore aα+1≡a1(modp), such that P(aα+1)=aα+12−b12+k≡0(modpα+1). This proves the induction.
- Last Step: We prove the general case when n=p1α1p2α2⋯plαl, where 7≤p1<p2<⋯<pl are prime numbers. We know from the second step, that for each i=1,2,…,l, there exist two integers ai,bi, relatively prime with pi, such that piαi divides ai2−bi2+k. From the Chinese remainder theorem, there exist two integers a,b such that a≡ai(modpiαi) and b≡bi(modpiαi), for i=1,2,…,l. Therefore,
a2−b2+k≡ai2−bi2+k≡0(modpiαi)
for all i=1,2,…,l, and hence
a2−b2+k≡0(modn).
On the other hand,
gcd(n,a)=i=0∏lgcd(piαi,ai)=1 and gcd(n,b)=i=0∏lgcd(piαi,bi)=1.
This completes the proof.