题目需求:
对于一个十进制的正整数, 定义f(n)为其各位数字的平方和,如:
f(13) = 12 + 32 = 10
f(207) = 22 + 02 + 72 = 53
下面给出三个正整数k,a, b,你需要计算有多少个正整数n满足a<=n<=b,
且k*f(n)=n
输入:
第一行包含3个正整数k,a, b, k>=1, a,b<=1018, a<=b;
输出:
输出对应的答案;
范例:
输入: 51 5000 10000 #51 * f(n) =n 5000<=n<=10000
输出: 3
s = input('') # '51 5000 10000' ==['51','5000','10000']
li = []
for item in s.split():
li.append(int(item))
k,a,b = li
def f(n):
# 1.先把数字转换成字符串
n = str(n)
# 2.计算字符串中每个数的平方
sum = 0
for item in n:
sum += int(item) ** 2
return sum
count = 0
for i in range(a,b+1):
if k * f(i) == i:
count +=1
print(count)