自守数

来源:互联网 发布:爱快路由 windows版 编辑:程序博客网 时间:2024/04/30 05:23

题目描述

自守数是指一个数的平方的尾数等于该数自身的自然数。例如:25^2 = 625,76^2 = 5776,9376^2 = 87909376。请求出n以内的自守数的个数


接口说明


/*
功能: 求出n以内的自守数的个数


输入参数:
int n

返回值:
n以内自守数的数量。
*/


public static int CalcAutomorphicNumbers( int n)
{
/*在这里实现功能*/

return 0;
}




输入描述:

int型整数



输出描述:

n以内自守数的数量。


输入例子:
2000

输出例子:
8
//自守数是指一个数的平方的尾数等于该数自身的自然数。例如:252 = 625,762 = 5776,93762 = 87909376。请求出n以内的自守数的个数////接口说明//原型://unsignedint CalcAutomorphicNumbers(unsignedint n);//输入参数://unsignedint n : n ≤ 232////返回值://n以内自守数的数量#include<iostream>#include<string>using namespace std;bool isAutomaticNum(int x){string str1 = to_string(x);string str2 = to_string(x*x);for (int i = 0; i < str1.size(); i++){if (str1[str1.size() - i - 1] != str2[str2.size() - i - 1])return false;}return true;}int main(){int x;while (cin >> x){int count = 0;while (x){if (isAutomaticNum(x))count++;x--;}cout << count+1 << endl;}}

0 0
原创粉丝点击