#include <stdio.h> #include <math.h> /** 这个函数用来求一个数有几位,例如12345有5位。 */ int sizes(int n) { int count=1; while(n/10!=0) { count++; n=n/10; } return count; } /** 这个函数用来求n^m,其中n,m均为整数。 */ long long mypow(int n,int m) { int i; long long s=1; for(i=1;i<=m;i++) { s=s*n; } return s; } int main() { int i,n; int a[50],count=0; for(i=0;i<=200000;i++) { n=sizes(i); /** 核心思路在下面这个if式子里 自守数的平方减去自守数,得到的值能够整除10的自守数的位数次方。 例如:9376^2=87909376 9376有4位, 87909376-9376=87900000 则 87900000 % 10^4 ==0 */ if( (mypow(i,2)-i) % mypow(10,n) == 0) { //将符合条件的值存入数组中,方便格式化输出 a[count]=i; count++; } } for(i=0;i<count;i++) { if(i==count-1) printf("%d",a[i]); else printf("%d ",a[i]);//天坑,这里要求两个空格 } return 0; }
0.0分
0 人评分
Biggest Number (C++代码)回溯法浏览:1653 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:922 |
Pascal三角 (C语言代码)格式错误浏览:549 |
【出圈】 (C语言代码)浏览:818 |
输出正反三角形 (C语言代码)浏览:853 |
【偶数求和】 (C语言代码)浏览:670 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:530 |
【排队买票】 (C语言代码)浏览:935 |
淘淘的名单 (C语言代码)浏览:1162 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:625 |