Emirp

20 篇文章 0 订阅
Emirp
Time Limit: 5000 MSMemory Limit: 100000 K
Total Submit: 143(59 users)Total Accepted: 61(55 users)Rating: Special Judge: No
Description

An emirp (prime spelled backwards) is a prime number that results in a different prime when its decimal digits are reversed.

The first five emirps are 13, 17, 31, 37, 71

Now Kim want to know the kth emirp. Help him.

Input

The first line is an integer T, describes the number of tests. Then T tests.

In each test, one line an integer k.

Output

For each test, output the kth emirp.

Sample Input
3
1
2
3
Sample Output
13
17
31
Hint

T<=10000

k<=1000

思路:就是找大于十的数使其本身和其反置都为素数,并且本身和其反置数不能相同。


#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[1000000];
int sushu(int n)
{
    int i,j;
    int k;
    k=sqrt(n);
    for(i=2;i<=k;i++)
    {
        if(n%i==0)
            break;
    }
    if(i>k)
        return 1;
    else
        return 0;
}
int main()
{

    int i,j,k,k1,b,c,d,t,sum;
    for(i=13,j=1; i<=70529; i++)
    {
        k=0;
        t=i;
        while(t>0)
        {
            k=k*10+t%10;
            t=t/10;
        }
        k1=i;
        if(sushu(k)==1&&sushu(k1)==1&&k1!=k)
        {
            a[j]=k1;
            j++;
        }
    }
    int n,m;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        printf("%d\n",a[m]);
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值