Skip to content

Commit 19c7a40

Browse files
Oleksandr Kulkovadamant-pwn
authored andcommitted
extra tab
1 parent cc3cf4a commit 19c7a40

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/algebra/continued-fractions.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -678,22 +678,22 @@ One can further prove (and it was first done by Lagrange) that for arbitrary qua
678678
```py
679679
# compute the continued fraction of sqrt(n)
680680
def sqrt(n):
681-
n0 = math.floor(math.sqrt(n))
682-
x, y, z = 1, 0, 1
683-
a = []
684-
def step(x, y, z):
685-
a.append((x * n0 + y) // z)
686-
t = y - a[-1]*z
687-
x, y, z = -z*x, z*t, t**2 - n*x**2
688-
g = math.gcd(x, math.gcd(y, z))
689-
return x // g, y // g, z // g
690-
691-
used = dict()
692-
for i in range(n):
693-
used[x, y, z] = i
694-
x, y, z = step(x, y, z)
695-
if (x, y, z) in used:
696-
return a
681+
n0 = math.floor(math.sqrt(n))
682+
x, y, z = 1, 0, 1
683+
a = []
684+
def step(x, y, z):
685+
a.append((x * n0 + y) // z)
686+
t = y - a[-1]*z
687+
x, y, z = -z*x, z*t, t**2 - n*x**2
688+
g = math.gcd(x, math.gcd(y, z))
689+
return x // g, y // g, z // g
690+
691+
used = dict()
692+
for i in range(n):
693+
used[x, y, z] = i
694+
x, y, z = step(x, y, z)
695+
if (x, y, z) in used:
696+
return a
697697
```
698698

699699
Using the same `step` function but different initial $x$, $y$ and $z$ it is possible to compute it for arbitrary $\frac{x+y \sqrt{n}}{z}$.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy