Difference Between Primes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3339    Accepted Submission(s): 953

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<iostream>
using namespace std;
const long N = 1000005;
long prime[N],num_prime;
int isNotPrime[N]= {1, 1};
void getprime()
{
    for(long i = 2 ; i < N ; i ++)
    {
        if(!isNotPrime[i])prime[num_prime ++]=i;
        for(long j = 0 ; j < num_prime && i * prime[j] <  N ; j ++)
        {
            isNotPrime[i * prime[j]] = 1;
            if(!(i%prime[j]))break;
        }
    }
}
int main()
{
    getprime();
    int T,n,s,a;
    cin>>T;
    while(T--)
    {
        cin>>n;
        a=n>0?n:-n;
        s=0;
        for(int i=0; i<100000; i++)
            if(!isNotPrime[prime[i]+a])
            {
                if(n>0) cout<<prime[i]+a<<" "<<prime[i]<<endl;
                else cout<<prime[i]<<" "<<prime[i]+a<<endl;
                s=1;
                break;
            }
        if(s==0)cout<<"FAIL"<<endl;
    }
    return 0;
}

HDU 4715:Difference Between Primes的更多相关文章

  1. HDU - 5936: Difference(暴力:中途相遇法)

    Little Ruins is playing a number game, first he chooses two positive integers yy and KK and calculat ...

  2. hdu 4715 Difference Between Primes

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

  3. HDU 4715 Difference Between Primes (打表)

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

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

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

  5. 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 ...

  6. HDU - 6409:没有兄弟的舞会(数学+思维)

    链接:HDU - 6409:没有兄弟的舞会 题意: 题解: 求出最大的 l[i] 的最大值 L 和 r[i] 的最大值 R,那么 h 一定在 [L, R] 中.枚举每一个最大值,那么每一个区间的对于答 ...

  7. POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)

    http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...

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

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

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

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

随机推荐

  1. MySQL半同步复制的安装和配置

    (1)检查master/slave是否支持动态加载插件 > show variables like 'have_dynamic_loading'; +---------------------- ...

  2. [转]Entity Framework技术导游系列开篇与热身

    学习Entity Framework技术期间查阅的优秀文章,出于以后方便查阅的缘故,转载至Blog,可查阅原文:http://blog.csdn.net/bitfan/article/details/ ...

  3. Excel将秒转换成标准的时间格式HH:MM:SS

    Excel将秒转换成标准的时间格式HH:MM:SS 比如120秒,转换成00:02:00 Excel公式为: =TEXT(A1/86400,"[hh]:mm:ss") A1为秒数据 ...

  4. js - ajax中的get和post说明

    转自:http://www.cnblogs.com/hateyoucode/archive/2009/12/09/1620050.html 一.谈Ajax的Get和Post的区别 Get方式:   用 ...

  5. M面经Prepare: Delete Words Starting With One Character

    给定一个char array, 这个array是一个句子,然后给定一个字母,把这个array里面带有这个字母开头的单次删掉,操作是要求in place. 检测   array[i]==' ' & ...

  6. PHP的基本语法

    PHP的基本语法和c#的基本语法是差不多的,在这里只和大家聊一下PHP和C#语法不同的地方. 首先 PHP和c#的标记方式不一样,PHP他是一门脚本语言,JS也是脚本语言,只不过JS是运行在客户端的, ...

  7. 活动组件(三):Intent

    大多数的安卓应用都不止一个Activity,而是有多个Activity.但是点击应用图标的时候,只会进入应用的主活动. 因此,前面我已经建立了一个主活动了,名字是myActivity,现在我再建立一个 ...

  8. 【皇甫】☀PPT里的小玩意

    第三次写博客了,感觉写的蛮有趣的,在写的同时,回顾了知识点,又上手操作了一遍,印象更加深刻了,尽管今天写的和那些像JAVA啦,HTML啦,C#啦,没多大关系(个人理解),但确实我们经常能用到的.比如说 ...

  9. 自定义view(使用EditTetx实现记事本特效)

    先看一下效果图: 思路: 创建一个类,继承自EditText,在onDraw方法中绘制我们的下划线,通过屏幕的高度和每行控件的高度的比值得出屏幕中应该绘制多少行下划线,再来实现一些自定义的属性,设置控 ...

  10. :nth-child()和:nth-of-type(n)区别

    ele:nth-child(n) 父元素下第n个元素且这个元素为ele ele:nth-of-type(n) 指父元素下第n个ele元素