标签:
/*
ID: awsd1231
PROG: dualpal
LANG: C++
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int maxn = 33;
int n, s;
char mayPal[maxn] = {0};
bool isPal(int xq) {
int count = 0;
for(int i = 2; i != 11; ++i) {
int x = xq;
memset(mayPal, 0, maxn);
int idx = 0;
bool canZero = false;
for(int j = maxn; j != -1; --j) {
if(!canZero && pow(i, j) > x) continue;
else {
canZero = true;
for(int k = i-1; k != -1; --k) {
if(k * pow(i, j) <= x) {
mayPal[idx++] = k +‘0‘;
x -= k * pow(i, j);
break;
}
}
}
}
int len = strlen(mayPal);
bool yes = true;
for(int j = 0; j < len/2; ++j) {
if(mayPal[j] != mayPal[len-j-1]) {
yes = false;
break;
}
}
if(yes) {
count++;
}
if(count == 2) return true;
}
return false;
}
int main() {
freopen("dualpal.in" ,"r", stdin);
freopen("dualpal.out", "w", stdout);
cin >> n >> s;
for(int i = s+1, t = 0; t != n; i++) {
if(isPal(i)) {
cout << i << endl;
t++;
}
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4541859.html