Problem Description
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 nidentified the count of test cases(n<10^5). There is a even number xat the next nlines. The absolute value of xis not greater than 10^6.
 
Output
For each number xtested, outputstwo primes aand bat one line separatedwith one space where a-b=x. If more than one group can meet it, output the minimum group. If no primes can satisfy it, output 'FAIL'.
 
Sample Input
3
6
10
20
 
Sample Output
11 5
13 3
23 3
 
Source
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; const int N= ;
int prime[],cnt;
bool isprime[N]; void Prime()
{
cnt =;
memset(isprime,true,sizeof(isprime));
isprime[]=false;
for(int i=; i<N; i++)
if(isprime[i])
{
for(int j=i+i; j<N; j+=i) isprime[j] = false;
prime[cnt++] = i;
}
} void finder(int m)
{
for(int i=; i<cnt; i++)
{
if(prime[i]>m && isprime[prime[i]-m])
{
printf("%d %d\n",prime[i],prime[i]-m);
return ;
}
}
puts("FAIL");
}
int main()
{
int t,m;
Prime();
scanf("%d",&t);
while(t--)
{
scanf("%d",&m);
finder(m);
} return ;
}

Difference Between Primes的更多相关文章

  1. hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...

  2. HDU 4715:Difference Between Primes

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  3. hdu 4715 Difference Between Primes

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Description All you kn ...

  4. HDU 4715 Difference Between Primes (打表)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  5. hdu 4715 Difference Between Primes (打表 枚举)

    Difference Between Primes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  6. hdu 4715 Difference Between Primes(素数筛选+树状数组哈希剪枝)

    http://acm.hdu.edu.cn/showproblem.php?pid=4715 [code]: #include <iostream> #include <cstdio ...

  7. hdu 4715 Difference Between Primes 2013年ICPC热身赛A题 素数水题

    题意:给出一个偶数(不论正负),求出两个素数a,b,能够满足 a-b=x,素数在1e6以内. 只要用筛选法打出素数表,枚举查询下就行了. 我用set储存素数,然后遍历set里面的元素,查询+x后是否还 ...

  8. hdoj 4715 Difference Between Primes 素数筛选+二分查找

    #include <string.h> #include <stdio.h> const int maxn = 1000006; bool vis[1000006]; int ...

  9. 【Difference Between Primes HDU - 4715】【素数筛法打表+模拟】

    这道题很坑,注意在G++下提交,否则会WA,还有就是a或b中较大的那个数的范围.. #include<iostream> #include<cstdio> #include&l ...

随机推荐

  1. 'EntityValidationErrors' property for more details

    很多小猿遇到这个Exception 的时候,都会有点无厘头.这个时候最好try-- catch下,找到出错的地方.本人习惯在页面上加个lable标签,把exc msg(exception messag ...

  2. The Better Way to Debug Your JavaScript Program

    Debugging JS program is not as easy as we do in Visual Studio or any other IDE. I usually us "a ...

  3. 关于java中for和foreach循环

    for循环中的循环条件中的变量只求一次值!具体看最后的图片 foreach语句是java5新增,在遍历数组.集合的时候,foreach拥有不错的性能. foreach是for语句的简化,但是forea ...

  4. SVM推导

    标准最大margin问题 假设data是linear seperable的 优化目标 希望 margin(w),i.e, 最小的点到直线的距离 最大 即是要得到最右的线,它对噪声的鲁棒性最好 得到的分 ...

  5. cell的循环使用

    cell的循环利用:(对cell的简单优化) 1.创建一个标示(Identifier),用于区分缓存池里的不同cell. 2.去缓存池里拿自己对应的cell,用到dequeueReusableCell ...

  6. HDU 5491 The Next

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  7. easyui-combobox小Demo

    <script type="text/javascript"> $("#Function_TypeSelect").combobox({ onSel ...

  8. node.Js学习-- 创建服务器简要步骤

    1.创建项目目录 mkdir ningha(文件夹名)npm init 初始化项目  获得package.json 2..在node.Js命令行操作进入到文件所在目录 3.输入browser-sync ...

  9. fedora安装sublime text教程

    下载 http://pan.baidu.com/s/1eRkEegM 解压 终端中切换到下载文件的目录下,执行以下命令: sudo tar -jxvf sublime_text_3_build_308 ...

  10. [Linux]关机和重启命令

     Linux中常用的关机和重新启动命令有shutdown.halt.reboot以及init,它们都可以达到关机和重新启动的目的,但是每个命令的内部工作过程是不同的,下面将逐一进行介绍. 1. shu ...