题目描述
自守数是指一个数的平方的尾数等于该数自身的自然数。例如:25^2 = 625,76^2 = 5776,9376^2 = 87909376。请求出n以内的自守数的个数
接口说明
/*
功能: 求出n以内的自守数的个数
输入参数:
int n
返回值:
n以内自守数的数量。
*/
public static int CalcAutomorphicNumbers( int n)
{
/在这里实现功能/
return 0;
}
输入描述:
int型整数
输出描述:
n以内自守数的数量。
示例1
输入
2000
输出
8
思路:自守数:(数x的平方-数x)%(10的数x长度次方)=0
def ifselfnum(x):
length=len(str(x))
if (x**2-x) % (10**length)==0:
return True
else:
return False
while True:
try:
n=int(input())
count=0
for i in range(n+1):
if ifselfnum(i):
count+=1
print(count)