It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.
The square root of two is 1.41421356237309504880..., and the digital sum of the first one hundred decimal digits is 475.
For the first one hundred natural numbers, find the total of the digital sums of the first one hundred decimal digits for all the irrational square roots.
难道是我理解错了!!the first one hundred decimal digits 这个意思不是说前一百位小数的数字??!!小数点前面的要算么!!总之最后是算上小数点前面的数提交才通过的(╯‵□′)╯︵┻━┻
具体方法参照的这里 这题感觉不只知道这个方法的话解决起来会有点麻烦
import math
def count(n):
limit=math.pow(10,102)
a=n*5
b=5
while b<limit:
if a>=b:
a=a-b
b=b+10
else:
a=a*100
if b!= 5:
b=(b-5)*10+5
b_str=str(b)
return b_str[:-3]
def digitalcount(s):
ans=0
c=0
for i in range(0,len(s)):
tmp=int(s[i])-int('0')
ans=ans+tmp
c=c+1
print(c)
return ans
ans = 0
j=1
for i in range(1,101):
if j*j==i:
j=j+1
continue
a=digitalcount(count(i))
ans=ans+a
print('ans = ',ans)