-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp080.py
More file actions
47 lines (40 loc) · 913 Bytes
/
p080.py
File metadata and controls
47 lines (40 loc) · 913 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
35
36
37
38
39
40
41
42
43
44
45
46
47
import math
def sqrt_gen(n):
c = n
p = ""
p2 = ""
while len(str(p)) < 100:
#x = int(-10*int(p) + math.sqrt(c+100*int(p)**2))
#y = x*(20*int(p) + x)
#if not p: p = str(x)
#else: p += str(x)
#r = c - y
#c = r*100
if not p:
x = int(math.sqrt(c))
y = x*x
else:
x = int(c/(20*float(p)))
y = x*(20*int(p) + x)
while y > c:
x -= 1
y = x*(20*int(p) + x)
while y <= c:
nx = x + 1
ny = nx*(20*int(p) + nx)
if ny <= c:
x = nx
y = ny
else:
break
#p = addDigit(p+"0",x)
#p2 = addDigit(p2 + "0",x*2)
p += str(x)
r = c - y
if r == 0: return 0
c = r*100
return sum(map(int,p))
total = 0
for i in range(101):
total += sqrt_gen(i)
print i,total