swustoj自守数(0485)
来源:互联网 发布:c语言开方函数 编辑:程序博客网 时间:2024/06/16 23:05
如果某个数的平方的末尾即尾数等于这个数,那么就称这个数为自守数。例如,5和6都是自守数(5x5=25 6x6=36)。同样,25x25=625 76x76=5776,所以25和76也是自守数。虽然0和1的平方的个位数仍然是0和1,但是他们太“平凡”了,研究他们没有意义,所以不算自守数。现在就请大家编写程序,来判断输入的数n(0≤n≤200000)是否为自守数。
Description
输入包含多组测试数据,要求处理到EOF(End Of Fiie)为止。
Input
输出判断结果,如果是自守数,输出为YES,不是自守数,输出为NO。
Output
1
2
3
4
5
0
25
78
109376
Sample Input
1
2
3
4
5
NO
YES
NO
YES
#include <iostream>#include<string.h>#include<math.h>using namespace std;int main(){ long long n;while (cin >> n){if (n == 0 || n == 1){cout << "NO" << endl;continue;}long long int b = n*n;int weishu = 0;long long temp = n;while (temp > 0){weishu++;temp /= 10;}int k = 1;weishu -= 1;while (weishu--){k = k * 10;}temp = b%(k*10);if (temp == n){cout << "YES" << endl;}else{cout << "NO" << endl;}}return 0;}
0 0
- swustoj自守数(0485)
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数!
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- Android 的滑动分析以及各种实现
- Mercury:唯品会全链路应用监控系统解决方案详解(含 PPT)
- Unity给力插件之ShaderForge(一)
- bzoj 4600 硬币游戏 博弈论
- atl异步线程调用js函数
- swustoj自守数(0485)
- saltstack--用户管理
- [美国签证]准备材料及面签过程
- 基于Jetson TX1的摄像头API函数例程
- Wix使用
- 【转】微信JS-SDK选择相册或拍照并上传PHP实现
- Oracle数据库建表 Oracle数据库的统一命名与编码规范
- Android实现简单购物车
- php面试题之三——PHP语言基础(基础部分)