sdnu1500.Problem_I (偶数写成两个质数的差 素数打表)

Description

Spring is coming, T_T.

 

       All you know Goldbach conjecture.That is to say, Every even integer greater than 2 can be expressed as the sum of two primes. Today, skywind present a new conjecture: every even integer can be expressed as the difference of two primes. To validate this conjecture, you are asked to write a program.

Input

The first line of input is a number n identified the count of test cases(n<10^4). There is a even number x at the next n lines. The absolute value of x is not greater than 10^6.

Output

For each number x tested, outputs two primes a and b at one line separated with one space where a-b=x. If more than one group can meet it, output the minimum group(of course refers b). If no primes can satisfy it, output 'FAIL'.

Sample Input

3
6
10
20

Sample Output

11 5
13 3
23 3

 把一个偶数写成两个质数的差   表打到1e7即可

#include <bits/stdc++.h>
using namespace std;
const int N=1e7+7;
int prime[N/10];
bool vis[N];
int tot=0;
void Er()
{
    memset(vis,0,sizeof(vis));
    vis[1]=vis[0]=1;
    for(int i=2;i<N;i++)
    {
        if(!vis[i])
        {
            prime[tot++]=i;
            for(int j=i+i;j<N;j+=i)
                vis[j]=1;
        }
    }
}
int main()
{
    Er();
//    for(int i=0;i<10;i++)
//        cout<<prime[i]<<'\n';
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int it=lower_bound(prime,prime+tot,n)-prime;
        bool f=0;
        for(int i=it;i<tot;i++)
        {
            if(!vis[prime[i]-n])
            {
                f=1;
                cout<<prime[i]<<' '<<prime[i]-n<<'\n';
                break;
            }
        }
        if(!f)
            cout<<"FAIL"<<'\n';
    }
    return 0;
}

 

全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 10:25
点赞 评论 收藏
分享
一颗宏心:华为HR晚上过了十二点后还给我法消息。
点赞 评论 收藏
分享
11-15 17:19
湖南大学 Java
成果成果成果果:这是哪个公司的hr,这么离谱吗,我没见过用性别卡技术岗的,身边女性同学拿大厂offer的比比皆是
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务