38 lines
576 B
Python
38 lines
576 B
Python
from math import sqrt, log10
|
|
|
|
|
|
def newton(a, n = 2):
|
|
x = 0
|
|
x_ = int(sqrt(a))
|
|
if x_ ** n == a:
|
|
return x_
|
|
while abs(x - x_) > 1:
|
|
x = x_
|
|
tmp = x ** (n - 1)
|
|
x_ = x - (tmp * x - a) / tmp / n
|
|
x_ = int(x_)
|
|
while x ** n > a:
|
|
x -= 1
|
|
return x
|
|
|
|
|
|
def numsum(x):
|
|
total = 0
|
|
while x != 0:
|
|
total += x % 10
|
|
x /= 10
|
|
return total
|
|
|
|
|
|
def main(maxx):
|
|
ss = 0
|
|
for i in xrange(maxx + 1):
|
|
if int(sqrt(i)) ** 2 == i:
|
|
continue
|
|
tmp = newton(i * 100 ** 99)
|
|
ss += numsum(tmp)
|
|
print ss
|
|
|
|
|
|
|