自守数
来源:互联网 发布:mac照片存在哪里 编辑:程序博客网 时间:2024/04/30 05:18
题目描述:
自守数是指一个数的平方的尾数等于该数自身的自然数。例如:252 = 625,762 = 5776,93762 = 87909376。请求出n以内的自守数的个数
接口说明:
/*
功能: 求出n以内的自守数的个数输入参数:
int n
返回值:
n以内自守数的数量。
*/
public static int CalcAutomorphicNumbers( int n)
{
/*在这里实现功能*/
return 0;
}
知识点: 查找
输入: int型整数
输出: n以内自守数的数量
样例输入: 2000
样例输出: 8
代码:
#include <iostream>#include <math.h>using namespace std;int Judge_WS(int num){int count = 0;while (num > 0){num /= 10;count++;}return count;}int main(){int num,i,weishu,count=0;cin >> num;for (i = 0; i <= num; i++){weishu = Judge_WS(i);int beichushu = pow(i, 2);int chushu = pow(10, weishu);if ((beichushu%chushu) == i)count++;}cout << count << endl;return 0;}参考代码:该题目有规律可循,比如只有这三个尾数的平方才可能是自身1^2=1,5^2=5,6^2=36。。。不知道怎么表述清晰。。。
#include <iostream> using namespace std; void main(void) { int n,count=0; scanf("%d",&n); for(int i=0;i<=n;i++) { int x=i%10; int temp; if(x==1 || x==5 || x==6 ) { int j=i; temp=i*i; while(j) { if(j%10 == temp%10) { j /= 10; temp /= 10; } else break; } if(!j) count++; } } cout<<count+1; }
0 0
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数!
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- 自守数
- python 一百行代码将图片转成字符画
- 旋转字符串 解题代码
- 关于javascript的一些内容
- String字符串转换成int[]数组
- DEV Gridcontrol 学习笔记
- 自守数
- leetcode--Bulb Switcher
- 控制Linux内核启动中的打印
- 自制发送短信程序(SmsManager与PendingIntent对象)
- 通用ListViewAdapter_ViewHolder
- UML之状态图
- appium mac 环境搭建
- cocos2dx 手柄
- HDU 5642 (DP)