AcWing 1346. 回文平方
原题链接
简单
作者:
sy123
,
2021-01-14 17:32:33
,
所有人可见
,
阅读 202
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string base(int n, int b)
{
string res;
while (n) res += n % b, n /= b;
reverse(res.begin(), res.end());
return res;
}
bool check(string s)
{
for (int i = 0, j = s.size() - 1; i < j; i ++, j -- )
if (s[i] != s[j])
return false;
return true;
}
int main()
{
int n,s;
cin >> n >> s;
int sum=0;
for (int i = s + 1; ; i ++ )
{
int cnt = 0;
for(int j = 2; j <= 10; j++){
string num = base(i, j);
if (check(num)){
cnt++;
if(cnt == 2){
cout<< i <<endl;
sum++;
break;
}
}
}
if(sum == n)break;
}
return 0;
}