题目描述
输出所有aabb式的4位完全平方数。千位百位相同,个位十位相同。
思路
总结就是要满足两个条件,第一个是平方数,第二个是要满足aabb式。
代码
- 先得到aabb式的数,然后开根号的数一定要是整数。
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
for(int i = 1; i <= 9; i++)
{
for(int j = 0; j <= 9; j++)
{
int n = i * 1100 + j*11;//n就是完全数
int m = floor(sqrt(n) + 0.5);
if(m*m == n)
{
printf("%d\n",n);
}
}
}
return 0;
}
- 先平方然后求aabb式的数
#include<iostream>
using namespace std;
int main()
{
int x, i;
for(i = 30; ;i++)
{
x = i * i;
if(x < 1000)
{
continue;
}
else if(x > 9999)
{
break;
}
else if((x / 1000 == x / 100 % 10) && (x % 10 == x % 100 / 10))
{
printf("%d",x);
}
}
}