summaryrefslogtreecommitdiff
path: root/1.3/dualpal.c
blob: caa516e81ea5797b4bc6927b52e684124fba4974 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
ID: mytbk921
LANG: C
TASK: dualpal
*/

#include <stdio.h>

int dualpal(int a) //check if a is dualpal
{
	int chk[32];
	int l,base,i;
	int count=0;
	for (base=10;base>=2;base--){
		l=0;
		for (chk[0]=a;chk[l];++l){
			chk[l+1]=chk[l]/base; //when chk[l+1]=0,the conversion is over
			chk[l]%=base;
		}
		for (i=0;i<l/2;i++){
			if (chk[i]!=chk[l-1-i])
				break;
		}
		if (i>=l/2)
			++count;
		if (count==2)
			return 1;
	}
	return 0;
}

int main()
{
	int n,s;
	FILE *fin=fopen("dualpal.in","r");
	FILE *fout=fopen("dualpal.out","w");
	fscanf(fin,"%d%d",&n,&s);
	fclose(fin);

	while (n){
		++s;
		if (dualpal(s)){
			fprintf(fout,"%d\n",s);
			--n;
		}
	}
	
	return 0;
}