自守数
2016-03-13 18:30
323 查看
题目描述:
自守数是指一个数的平方的尾数等于该数自身的自然数。例如:252 = 625,762 = 5776,93762 = 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以内的自守数的个数
接口说明:
/*
功能: 求出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; }
相关文章推荐
- spring管理hibernate的SessionFactory-多种配置方法
- UML之状态图
- 文本框和文本视图(NSTextField、NSTextView)
- 线性回归&梯度下降
- javascript中的BOM与DOM、JS核心
- (java) 第二周学习总结
- HTTP stub_status 模块
- PHP Undefined index报错的修复方法
- CentOS 6.7-jdk
- java 文件类File 文本I/O
- java改变png图片的透明度
- IOS中如何切换到主线程工作
- 设计模式_适配器模式
- cocos2dx 手柄
- appium mac 环境搭建
- 数据可视化-工具软件
- neutron中的dhcp功能
- 函数式编程
- VS2012 OpenCV2.4.9 Debug可以允许,Release不可以
- 通用ListViewAdapter_ViewHolder