28
5
Given some positive integer \$n\$ that is not a square, find the fundamental solution \$(x,y)\$ of the associated Pell equation
$$x^2 - n\cdot y^2 = 1$$
Details
- The fundamental \$(x,y)\$ is a pair of integers \$x,y\$ satisfying the equation where \$x\$ is minimal, and positive. (There is always the trivial solution \$(x,y)=(1,0)\$ which is not counted.)
- You can assume that \$n\$ is not a square.
Examples
n x y
1 - -
2 3 2
3 2 1
4 - -
5 9 4
6 5 2
7 8 3
8 3 1
9 - -
10 19 6
11 10 3
12 7 2
13 649 180
14 15 4
15 4 1
16 - -
17 33 8
18 17 4
19 170 39
20 9 2
21 55 12
22 197 42
23 24 5
24 5 1
25 - -
26 51 10
27 26 5
28 127 24
29 9801 1820
30 11 2
31 1520 273
32 17 3
33 23 4
34 35 6
35 6 1
36 - -
37 73 12
38 37 6
39 25 4
40 19 3
41 2049 320
42 13 2
43 3482 531
44 199 30
45 161 24
46 24335 3588
47 48 7
48 7 1
49 - -
50 99 14
51 50 7
52 649 90
53 66249 9100
54 485 66
55 89 12
56 15 2
57 151 20
58 19603 2574
59 530 69
60 31 4
61 1766319049 226153980
62 63 8
63 8 1
64 - -
65 129 16
66 65 8
67 48842 5967
68 33 4
69 7775 936
70 251 30
71 3480 413
72 17 2
73 2281249 267000
74 3699 430
75 26 3
76 57799 6630
77 351 40
78 53 6
79 80 9
80 9 1
81 - -
82 163 18
83 82 9
84 55 6
85 285769 30996
86 10405 1122
87 28 3
88 197 21
89 500001 53000
90 19 2
91 1574 165
92 1151 120
93 12151 1260
94 2143295 221064
95 39 4
96 49 5
97 62809633 6377352
98 99 10
99 10 1
Surprised that there isn't any challenge with the Pell equation yet, since it's pretty well-known I thought. At least, I do remember using it sometimes with Project Euler challenges. – Kevin Cruijssen – 2019-04-16T14:00:58.920
@Fatalize "You can assume that $n$ is not a square." Would probably be clearer if the test cases omitted those imho, though. – Kevin Cruijssen – 2019-04-16T14:05:59.740
2@KevinCruijssen I considered that, but I thought it would be more confusing to omit some of the
n
s. (btw I was also surprized but I had this challenge in the sandbox for about a year) – flawr – 2019-04-16T15:13:34.420Related: https://projecteuler.net/problem=66
– steenbergh – 2019-04-18T14:17:54.160