这个就是简单的进制转换加回文判断,其他方面的逻辑自己控制一下就好。
/*
ID: 13913351
LANG: C
TASK:dualpal
*/
#include<stdio.h>
#include<string.h>
char num[21]={"0123456789ABCDEFGHIJ"};
void shift(int m,int n,char res[32])
{
int k=0;
while(n!=0)
{
res[k++]=num[n%m];
n/=m;
}
res[k]='\0';
}
int judge(char res[32])
{
for(int j=0;j<strlen(res)/2;j++)
{
if(res[j]!=res[strlen(res)-j-1])
{
return 0;
}
}
return 1;
}
int main()
{
FILE *fin = fopen ("dualpal.in", "r");
FILE *fout = fopen ("dualpal.out", "w");
int N,S;
fscanf(fin,"%d%d",&N,&S);
int count=0;
while(1)
{
S++;
int i,j;
int sum=0;
int flag=0;
char res[32];
for(i=2;i<=10;i++)
{
shift(i,S,res);
if(judge(res))
{
sum++;
if(sum==2)
{
flag=1;break;
}
}
}
if(flag==1)
{
count++;
fprintf(fout,"%d\n",S);
if(count==N)break;
}
}
return 0;
}