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. [Machine Learning] Probabilistic Graphical Models:一、Introduction and Overview(1、Overview and Motivation)

    一.PGM用来做什么 1.  医学诊断:从各种病症分析病人得了什么病,该用什么手段治疗 2.  图像分割:从一张百万像素级的图片中分析每个像素点对应的是什么东西 两个共同点:(1)有非常多不同的输入变 ...

  2. 彻底删除sql2008r2

    一.    SQL2008卸载. 1.从控制面板卸载 1)点击计算机右下角“开始”,点击“控制面板” 2)点击“卸载程序”. 3)在程序列表中找到“Microsoft SQL Server 2008” ...

  3. js 高级函数 之示例

    js 高级函数作用域安全构造函数 function Person(name, age)    {        this.name = name;        this.age = age;     ...

  4. [转] 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 ---张鑫旭

    by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3804 去年盛夏之时, ...

  5. Apache 支持PHP

    ①加载PHP模块到Apache中: LoadModule php5_module "d:\php5\php5apache2_2.dll"   ②加入识别扩展名为.php文件(也可以 ...

  6. QSslError 类

    QSslError Class Header: #include <QSslError> qmake: QT += network Since: Qt 4.3 注意:这个类中的所有函数都是 ...

  7. 简单学C——第三天

    控制结构(二)     前面我们已经了解到了,控制结构中的判断结构,当然switch语句也是判断语句.不过如果if...else...语句你会了,我相信switch语句你也一定会的,它们的功能都是差不 ...

  8. 反射 DataTable拓展方法 转实体对象、实体集合、JSON

    Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalizatio ...

  9. 解决delphi使用sqlite时中文最后一个字是乱码的问题

    给部门同事写了个自动生成测试用例执行情况图表的工具,使用的sqlite3,遇到中文分别使用UTF8Encode和UTF8Decode进行处理,可还是出现了某些字段从数据库中读出时,最后一个汉字是乱码的 ...

  10. SQL Server日期函数之获得一个月中的天数

    SQL Server日期函数之获得一个月中的天数在实际中的应用比例还是占为多数的,如果你对这一技术,心存好奇的话,以下的文章将会揭开它的神秘面纱,望会在以后的学习或是工作中带来很大的帮助. 获得一个月 ...