题目:
http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2323
1,打表的姿势不对。。。
2,不会用sprintf和atoi函数实现倒转一个数字
题解:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
_Bool check[] = { };
int emirp[];
void make_prime(void)
{
int i, j;
for (i = ; i <= ; i++)
{
for (j = * i; j <= ; j += i)
{
check[j] = ;
}
}
}
void make_Emirp(void)
{
int i, j;
char string[];
int count = ;
int p, q,temp;
for (i = ; count <= ; i++)
{
if (!check[i])
{
sprintf(string, "%d", i);
for (p = , q = strlen(string) - ; p < q; p++, q--)
{
temp = string[p];
string[p] = string[q];
string[q] = temp;
}
int result = atoi(string);
if (!check[result] && result != i) emirp[count++] = i;
}
}
}
int main(void)
{
int t;
int k;
scanf("%d", &t);
make_prime();
make_Emirp();
while (t--)
{
scanf("%d", &k);
printf("%d\n", emirp[k - ]);
}
return ;
}