AcWing 1347. 双重回文
原题链接
简单
作者:
Vason
,
2024-04-14 19:47:42
,
所有人可见
,
阅读 1
浅浅写一下代码
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n, s;
bool change(int n, int m)
{
vector<int> a;
while(n)
{
a.push_back(n % m);
n /= m;
}
for(int i = 0, j = a.size() - 1; i <= j; i ++, j --)
if(a[i] != a[j]) return false;
return true;
}
bool check(int n)
{
int cnt = 0;
for(int i = 2; i <= 10; i ++)
if(change(n, i))
if(++ cnt >= 2) return true;
return false;
}
int main()
{
cin >> n >> s;
for(int i = s + 1; ; i ++)
{
if(check(i)) cout << i << endl, n --;
if(!n) break;
}
return 0;
}