ProgramAlgTrain/20240823/十四届蓝桥比赛/八进制回文平方数.cpp

41 lines
717 B
C++
Raw Normal View History

2024-09-17 10:55:15 +00:00
#include<iostream>
2024-09-18 03:16:49 +00:00
#include<cmath>
2024-09-17 10:55:15 +00:00
#include<sstream>
2024-08-23 13:44:31 +00:00
using namespace std;
2024-08-24 09:20:59 +00:00
// bool is_pf(int n){
// int a = sqrt(n);
// if(a*a==n){
// return true;
// }else{
// return false;
// }
// }
2024-08-23 13:44:31 +00:00
bool is_huiwen(int n){
stringstream ss;
ss<<std::oct<<n;
string bjz(ss.str());
int j=bjz.size()-1;
2024-08-30 10:19:48 +00:00
for(int i=0;i<(int)bjz.size();++i,--j){
2024-08-23 13:44:31 +00:00
if(bjz[i]!=bjz[j]){
return false;
}
}
return true;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n;
cin>>n;
2024-08-24 09:20:59 +00:00
const int sqrt_n = sqrt(n);
for(int i=1;i<=sqrt_n;i++){
if(is_huiwen(i*i)){
cout<<i*i<<" ";
2024-08-23 13:44:31 +00:00
}
}
cout<<endl;
}