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. Servie学习总结

    一.什么是Service Service是一个应用程序组件,它是安卓实现程序后台运行的一个解决方案. 二.分类 服务有两种类别started.bound.但是一个服务类所要继承的类是一样的,都是Ser ...

  2. 查看当前使用的shell

    1.实时查看当前进程中使用的shell种类:推荐 ps | grep $$ | awk '{print $4}' (注:$$表示shell的进程号) 2.最常用的查看shell的命令,但不能实时反映当 ...

  3. C# 控制台程序 托盘图标 事件响应

    static void Main(string[] args) { NotifyIconHelper ni = new NotifyIconHelper(); NotifyIconHelper.Sho ...

  4. 《转》前端性能优化----yahoo前端性能团队总结的35条黄金定律

    除了自己总结:1. 减少http请求,2.压缩并优化js/css/image 3.尽量静态页面,从简原则 4.代码规范(详见:个人知识体系思维导图) 从yahoo 新学到的: 网页内容 减少http请 ...

  5. PHP临时文件session的分级存储与定期删除

    在Windows上PHP默认的Session服务端文件存放在C:\WINDOWS\Temp下,如果说并发访问很大或者 session建立太多,目录下就会存在大量类似sess_xxxxxx的sessio ...

  6. How To Read a Paper.md

    @ Titile How To Read a Paper.md @ author Keshav, 译 uuplusu   # 1. Intro    1. 读论文重要    2. 没有人教    3. ...

  7. oracle简单两个操作

    sqlplus sys/密码 as sysdba ALTER USER 账号 IDENTIFIED BY 新密码; select *  from (select rownum 别名 ,表名.* fro ...

  8. 1.document.write(""); 输出语句

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  9. jQuery提供的小方法

    jQuery提供的小方法: 1.选择器 + 事件 + 函数 = 复杂的交互 2.循环处理与选择器匹配的各个元素:each() $("#").each(function(){     ...

  10. IS about 64bit system

    This function supports the 64-bit parts of the registry by using the REGDB_OPTION_WOW64_64KEY option ...