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
| #include <bits/stdc++.h> using namespace std;
char get(int x) { if(x<=9) return x+'0'; return x-10+'A'; } string base(int n,int b) { string num; while(n)num+=get(n%b),n/=b; reverse(num.begin(),num.end()); return num; }
bool check(string num) { for(int i=0,j=num.size()-1;i<j;i++,j--) if(num[i]!=num[j]) return false; return true; } int main() { int b; cin>>b; for(int i=1;i<=300;i++) { auto num= base(i*i,b); if(check(num)) cout<<base(i,b)<<' '<<num<<endl; } return 0; }
|