from decimal import getcontext, Decimal def main():
n = int(raw_input())
p = int(raw_input()) getcontext().prec = p+10 # 扩大精度,保证接过
sum = 0 for i in range(1,n+1):
nTemp = Decimal(i).sqrt()
if nTemp._isinteger() : # 自生函数的判断
sum += 0
else:
nTemp = str(nTemp)
for _ in range(p+1): # 空下来一个.,所以+1
if nTemp[_] != '.':
sum += int(nTemp[_]) print sum main()
学习
抽象化理解题目
边界值问题
错误
读题不仔细
Link:
https://www.hackerrank.com/contests/projecteuler/challenges/euler080