版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuxiangaaaaa/article/details/78082420
求一千万以下的自守数 如 5*5=25 25*25=625 如果有n由k位数构成 那么n的平方的末尾k位数必须和n相等 并且变量只能用证书
/**
* 思路:n的平方对整的x次幂取余结果是n,则满足条件
* 例5*5=25 25%10=5
* 625*625=390625 625%(10*10*10)=625
* @author yx
*
* 2017-9-25
*/
public class Test {
public static void main(String[] args) {
for (int j = 0; j < 10000000; j++) {
for (int i = 1; i < String.valueOf(j).length(); i++) {
if (Math.pow(j % (Math.pow(10, i)), 2) == j) {
System.out.println(j + "," + (int) (j % (Math.pow(10, i))));
break;
}
}
}
}
}
结果:
25,5
36,6
625,25
5776,76
141376,376
390625,625