|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/*找出10000以内的同构数
同构数 376*376=141376
思路:1、输入一个数num 先判断是几位数。记住数位length。
2、然后算它(num)的平方, square。
3、取square的后length位的数值temp
4、temp与num相等,则是同构数。
*/
#include <iostream>
#include <math.h>
using
namespace
std;
int
wei(
int
n)
//判断是几位数
{
if
(n>0&&n<10)
return
1;
else
if
(n>=10&&n<100)
return
2;
else
if
(n>=100&&n<1000)
return
3;
else
if
(n>=1000&&n<10000)
return
4;
else
return
5;
}
int
main()
{
long
num,sqaure;
long
temp;
for
(num=100;num<=10000;num++)
{
sqaure=num*num;
temp=sqaure%(
int
)
pow
(10,wei(num));
//取后num平方的后几位数字与num比较
if
(temp==num)
{
cout<<num<<
"*"
<<num<<
"="
<<sqaure<<endl;
}
}
return
0;
}
|