自守数
来源:互联网 发布:爱快路由 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
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数!
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- iOS 使用AFN for 循环上传多张图片至服务器,用户手机项目上面的图片顺序查看
- YII2框架引用js以及css 文件
- C和C++的区别?如何学习C++?(转)
- Why C++ Is Not “Back”
- 知乎爬虫之1:开篇序言
- 自守数
- 【Derivation】任何矩阵都相似与Jordan标准形证明
- Spring配置文件applicationContext.xml 找不到的问题
- addEventLoad
- HashSet去重
- 《Servlet与JSP核心编程》学习笔记-20161128
- 一些 Linux 桌面小技巧
- Android Notification的完整例子
- Android Studio & Typora 快捷键