from math import isqrt
from fractions import Fraction
def generate_continued_fraction(n):
a0 = isqrt(n)
is_square = a0**2 == n
step = 0
r, s = 0, 1
while True:
if step > 0 and is_square:
yield 0
else:
a = (r + a0) // s
r = a * s - r
s = (n - r**2) // s
step += 1
yield a
n = 403
sqrt_n = n**0.5
gen = generate_continued_fraction(n)
last_num, last_den = 1, 0
num, den = isqrt(n), 1
start = False
while 1:
r = next(gen)
if not start:
start = True
stop = 2 * r
else:
_n, _d = num, den
num, den = num * r + last_num, den * r + last_den
last_num, last_den = _n, _d
x = num % n
a = pow(x, 2, n)
if a < 2 * sqrt_n and sqrt_n < x < n - sqrt_n:
print(x)
if r == stop:
break
To embed this program on your website, copy the following code and paste it into your website's HTML: