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. Http协议、线程、线程池

    Socket模拟服务端运行代码: 1:启动服务端监听的服务,并接受客户端的连接 1.1 创建Socket Socket listenSocket=new Socket(AddressFamily.In ...

  2. 【基础】Oracle 表空间和数据文件

    多个表空间的优势:1.能够将数据字典与用户数据分离出来,避免由于字典对象和用户对象保存在同一个数据文件中而产生的I/O冲突2.能够将回退数据与用户数据分离出来,避免由于硬盘损坏而导致永久性的数据丢失3 ...

  3. wget 使用技巧

    wget 是一个命令行的下载工具.对于我们这些 Linux 用户来说,几乎每天都在使用它.下面为大家介绍几个有用的 wget 小技巧,可以让你更加高效而灵活的使用 wget. $ wget -r -n ...

  4. 关于项目既要使用ant脚本又要使用maven pom.xml文件的问题

    背景:项目使用的是ant脚本打包,但又需要maven去执行sonar代码扫描.所以项目中既有build.xml又有pom.xml build.xml设置的打包后产物文件夹为target,maven运行 ...

  5. boost::bind实践

    第一部分源码为基础实践: /*Beyond the C++ Standard Library ( An Introduction to Boost )[CN].chm*/ /*bind的用法*/ #i ...

  6. new、delete用法(一)

    第一部分:new的使用: #define DEBUG_NEW new(THIS_FILE, __LINE__)解释 THIS_FILE:表示当前类所处的文件名: __LINE__:表示分配内存操作所在 ...

  7. jquery fancybox ie6无法显示关闭按钮

    解决办法: 打开jquery.fancybox-1.3.4.css 注释掉这行就行了: .fancybox-ie6 #fancybox-close { background: transparent; ...

  8. WPF学习(一)控件的公共属性

    Visiblity控件是否可见:枚举类型:Visible表示可见.Collapsed不可见. IsEnabled:控件是否可用:bool类型. Background:背景色. FontSize:字体大 ...

  9. webapp框架—学习AngularUI1(demo折腾)

    angularUI下载地址:https://github.com/Clouda-team/BlendUI 下载解压后,demo在根目录 现在测试官网demo的使用 用浏览器打开mobile-angul ...

  10. Android App的生命周期是什么

    怎么说呢 看Android一般指的是 Activity的生命周期, 关于app的生命周期, 有明白的大神请告诉我 上面这张图是 网上搜到的一张关于app生命周期的图, 在我看来, 其实就是一个Acti ...