Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Pells-equation/FreeBASIC/pells-equation.basic
Normal file
24
Task/Pells-equation/FreeBASIC/pells-equation.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
Sub Fun(Byref a As LongInt, Byref b As LongInt, c As Integer)
|
||||
Dim As LongInt t
|
||||
t = a : a = b : b = b * c + t
|
||||
End Sub
|
||||
|
||||
Sub SolvePell(n As Integer, Byref a As LongInt, Byref b As LongInt)
|
||||
Dim As Integer z, r
|
||||
Dim As LongInt x, y, e1, e2, f1, f2
|
||||
x = Sqr(n) : y = x : z = 1 : r = 2 * x
|
||||
e1 = 1 : e2 = 0 : f1 = 0 : f2 = 1
|
||||
While True
|
||||
y = r * z - y : z = (n - y * y) / z : r = (x + y) / z
|
||||
Fun(e1, e2, r) : Fun(f1, f2, r) : a = f2 : b = e2 : Fun(b, a, x)
|
||||
If a * a - n * b * b = 1 Then Exit Sub
|
||||
Wend
|
||||
End Sub
|
||||
|
||||
Dim As Integer i
|
||||
Dim As LongInt x, y
|
||||
Dim As Integer n(0 To 3) = {61, 109, 181, 277}
|
||||
For i = 0 To 3 ''n In {61, 109, 181, 277}
|
||||
SolvePell(n(i), x, y)
|
||||
Print Using "x^2 - ### * y^2 = 1 for x = ##################### and y = #####################"; n(i); x; y
|
||||
Next i
|
||||
Loading…
Add table
Add a link
Reference in a new issue