xiaoyunhao
2024-11-17 17:00:27
求 225 后连续七个数字和为完全平方数的完全平方数
枚举每个起点,如果符合要求就输出。
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int pd(int x){
int ans=0;
while(x>0){
ans+=x%10;
x/=10;
}
int s=int(sqrt(ans));
return ans==s*s;
}
int main() {
for(int i=16;;i++){//枚举起点
int sum=i*i;
if(pd(i*i)&&pd((i+1)*(i+1))&&pd((i+2)*(i+2))&&pd((i+3)*(i+3))&&pd((i+4)*(i+4))&&pd((i+5)*(i+5))&&pd((i+6)*(i+6))){//判断
cout<<i<<" "<<i*i<<endl;
cout<<i+1<<" "<<(i+1)*(i+1)<<endl;
cout<<i+2<<" "<<(i+2)*(i+2)<<endl;
cout<<i+3<<" "<<(i+3)*(i+3)<<endl;
cout<<i+4<<" "<<(i+4)*(i+4)<<endl;
cout<<i+5<<" "<<(i+5)*(i+5)<<endl;
cout<<i+6<<" "<<(i+6)*(i+6)<<endl;
break;
}
}
return 0;
}