描述
自守数是指一个数的平方的尾数等于该数自身的自然数。例如:252 = 625,762 = 5776,93762 = 87909376。请求出n以内的自守数的个数
接口说明
/*
功能: 求出n以内的自守数的个数
输入参数:
int n
返回值:
n以内自守数的数量。
*/
public static int CalcAutomorphicNumbers( int n)
{
/在这里实现功能/
return 0;
}
知识点 查找
运行时间限制 10M
内存限制 128
输入
int型整数
输出
n以内自守数的数量。
样例输入 2000
样例输出 8
#include<iostream>
#include<iomanip>
using namespace std;
bool is_ZSH(long int n){
if (n == 0) return true;
long int x;
x = n*n;
while (n){
if (n % 10 == x % 10){
n /= 10;
x /= 10;
}
else{
return false;
}
}
return true;
}
int main(){
long int n;
cin >> n;
int cnt = 0;
for (int i = 0; i <= n; i++){
if (is_ZSH(i)){
cnt++;
}
}
cout << cnt << endl;
return 0;
}