-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp064.py
More file actions
37 lines (31 loc) · 735 Bytes
/
Copy pathp064.py
File metadata and controls
37 lines (31 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def periodr(a, b, c, b0):
if c==1 and b == b0:
return 0
else:
cn = (a - (b**2))//c
q = (-b0-b)//cn
bn = -b-(cn*q)
return 1 + periodr(a, bn, cn, b0)
def period(n):
a = n
c = 1
b = -isqrt(a)
b0 = b
# print('a=%d b=%d c=%d b0=%d' % (a, b, c, b0))
cn = (a - (b**2))//c
q = (-b0-b)//cn
bn = -b-(cn*q)
# print('a=%d bn=%d cn=%d b0=%d' % (a, bn, cn, b0))
return 1 + periodr(a, bn, cn, b0)
def isqrt(n):
y, x = n, n+1
while y < x:
x = y
y = (x + n//x)//2
return x
if __name__ == '__main__':
cnt = 0
for n in range(2, 10001):
if isqrt(n)**2 != n and period(n)%2==1:
cnt += 1
print(cnt)