### Testing Dujella's unicity conjecture

The conjecture states that the diophantine equation x2 – (k2 + 1)y2 = k2 has at most one positive solution (x,y) with 1 ≤ y < k – 1. (For background, see slides.)

This program deals with an equivalent diophantine equation, namely X2 – (k2 + 1)Y2 = -k2. The positive integral solutions (x,y) with 1 ≤ y < k –1 are in 1-1 correspondence with the positive solutions (X,Y) with 1 < Y < k of the equation X2 – 1 = (k2 + 1)(Y2 – 1) under the mapping x = (k2 – 1)Y – kX, y = kY – X. (This was observed by John Robertson.)

So Dujella's unicity conjecture is equivalent to there being at most one positive integer solution (X,Y) satisfying 1 < Y < k. In fact we can show that such a solution must satisfy Y < k/2, which implies 1 < X < (k2 + 1)/2.
Accordingly, we look for solutions of the congruence X2 ≡ 1 mod(k2 + 1) satisfying 1 < X < (k2 + 1)/2 and for which (X2 – 1)/(k2 + 1) = Y2 – 1. Note that if k is odd, then k2 + 1 = 2(2m + 1).

We test the conjecture for k in the range m ≤ k ≤ n, where n < 105, exhibiting the k for which an exceptional solution exists.

Enter m (1 < m < 105 ):
Enter n (1 < m ≤ n < 105 ):