dualpal.c # include <stdio.h> int N,S; int count=0; char num[11]="0123456789"; char n[21];
jinzhi(int i,int njz) { memset(n,'\0',sizeof(n)); int j=0; char t; int x=0,y; while(i>=njz) { n[j]=num[i%njz]; i/=njz; j++; }
if (i==0) n[j]='\0'; else n[j]=num[i],n[j+1]='\0'; y=strlen(n)-1; while (x<=y) { t=n[x]; n[x]=n[y]; n[y]=t; x++; y--; } } int palindromic() { int i=0,j; j=strlen(n)-1; while (i<=j) { if (n[i]!=n[j]) return (0); i++; j--; } return (1); }
main () { FILE *in=fopen("dualpal.in","r"); FILE *out=fopen("dualpal.out","w"); int i,j,right; fscanf (in,"%d%d",&N,&S); for (i=S+1;count<N;i++) { right=0; for (j=2;j<=10;j++) { jinzhi(i,j); if (palindromic()==1) right++; if (right==2) break; } if (right==2) { fprintf(out,"%d\n",i); count++; } }