> Run 1: Execution error: Your program had this runtime error:
Illegal file open (/dev/tty). The program ran for 0.000 CPU
seconds before the error. It used 2320 KB of memory.
/*
ID: nenusb1
LANG: C
TASK: dualpal
*/
#include <stdio.h>
#include <string.h>
int ifPal(char numStr[12]){
int len = strlen(numStr);
int f,t;
f=0,t=len-1;
while(f>=0 && t<len && f<=t){
if(numStr[f]==numStr[t]){f++;t--;}
else break;
}
if(f>t) return 1;
else return 0;
}
//itoa
void myItoa(int value, char str[12], int base){
int i=0;
while(pow(base,i)<=value){
i++;
}
int len = --i;
str[len+1] = '\0';
char c[1];
while(value>=0 && i>=0){
double dp = pow(base,i);//如果是用int p = ((int)pow(base,i)),pow(5,2)=25.0000会变成24!
int p = (int)dp;
//printf("value=%d p=%d ",value,p);
int div = value/p; //as base<=10, so intValue must be less than 10
value = value%p;
//printf("div=%d mod=%d\n",div,value);
//convert single int to char
char c[1];
sprintf(c,"%d",div);
str[len-i] = c[0];
i--;
}
}
int main(){
freopen("dualpal.in","r",stdin);
freopen("dualpal.out","w",stdout);
int n, s;
scanf("%d %d",&n,&s);
int num, count;
count = 0;
for(num = s+1;count<n;num++){
char numToString[12];
int base;
int palCount = 0;
for(base = 2; base<=10; base++){
myItoa(num,numToString,base);
if(ifPal(numToString)){ palCount++;}
if(palCount == 2) {printf("%d\n", num); count++; break;}
}
}
return 0;
}