对于一个十进制的正整数, 定义f(n)为其各位数字的平方和,如:
f(13) = 1** 2 + 3** 2 = 10
f(207) = 2** 2 + 0** 2 + 7** 2 = 53
下面给出三个正整数k,a, b,你需要计算有多少个正整数n满足a<=n<=b,且k*f(n)=n
输入:
第一行包含3个正整数k,a, b, k>=1, a,b<=10**18, a<=b;
输出:
输出对应的答案;
范例:
输入: 51 5000 10000 #51 * f(n) =n 5000<=n<=10000
输出: 3
def f(n):
n = str(n)
sum = 0
for item in n:
sum += int(item) ** 2
return sum
s = input('')
print(type(s))
li = []
for item in s.split():
li.append(int(item))
print(li)
k, a, b = li
print(k, a, b)
count = 0
for i in range(a, b + 1):
if k * f(i) == i:
count += 1
print(count)
结果是:
51 5000 10000
<class 'str'>
[51, 5000, 10000]
51 5000 10000
3