Difference Between Primes

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 832    Accepted Submission(s): 267

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
 
Recommend
liuyiding
 
快速打素数表:
代码:
代码敲上去较为匆忙!,请自己优化......62ms
 #include<iostream>
#include<cstdio>
#define maxn 1000000
using namespace std;
int prime[];
bool bo[maxn+];
int prime_table()
{
int i,j,flag=;
memset(bo,,sizeof bo);
bo[]=bo[]=;
for(i=; i*i<=maxn;i++)
{
if(!bo[i])
{
for(j=i*i;j<=maxn;j+=i)
bo[j]=;
}
}
for(i=;i<=maxn;i++)
if(!bo[i]) prime[flag++]=i;
return flag;
}
bool isprime(int a)
{
for(int i=;prime[i]*prime[i]<=a;i++)
{
if(a%prime[i]==)
return ;
}
return ;
} int main()
{
int i,t,b,num;
num=prime_table();
scanf("%d",&t);
while(t--)
{
scanf("%d",&b);
if(b>=)
{
for(i=;i<num;i++)
{ if(isprime(b+prime[i]))
{
printf("%d %d\n",prime[i]+b,prime[i]);
break;
}
}
}
else
{
for(i=;i<num;i++)
{ if(isprime(prime[i]-b))
{
printf("%d %d\n",prime[i],prime[i]-b);
break;
}
}
}
}
return ;
}
 

HDUOJ-----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. Difference Between Primes

    Problem Description All you know Goldbach conjecture.That is to say, Every even integer greater than ...

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

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

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

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

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

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

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

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

随机推荐

  1. java程序的运行方式

    1.JAR File JAR 文件用于压缩和发布,而且还用于部署和封装库.组件和插件程序,并可被像编译器和 JVM 这样的工具直接使用 有点类似于net中的dll 2.Runnable JAR Fil ...

  2. 如何让Oracle表及字段显示为区分大小写(转)

    http://www.itpub.net/thread-1703955-1-1.html

  3. 关于JSONP以及跨域相关

    什么是跨域: 浏览器对ajax请求的限制,不允许跨域请求资源. http://www.a.com--->http://www.b.com       是跨域 http://www.a.com-- ...

  4. 使用 kubeadm 搭建 kubernetes1.10 集群

    PS:所有节点安装之前记得先把镜像准备好,否者将无法启动,也不报错. $ cat /etc/hosts192.168.11.1 master192.168.11.2 node 禁用防火墙: $ sys ...

  5. JMS基本概念之一

    The Java Message Service(JMS) API is a messaging standard that allows application components based o ...

  6. 我所遭遇过的游戏中间件--Havok

    我所遭遇过的游戏中间件--Havok Havok是我接触的第一款游戏中间件,那是在五,六年前,我刚刚毕业,对游戏开发还是个菜鸟.我记得先是对游戏场景中的地形和其他静态物体生成刚体,然后做角色的Ragd ...

  7. 第十一章 自己实现一致性hash算法

    关于一致性hash算法的意义以及其相对于简单求余法(除数求余法)的好处,查看第六章 memcached剖析 注意:真实的hash环的数据结构是二叉树,这里为了简便使用了列表List 1.一致性hash ...

  8. 编写和执行C#代码的插件:CS-Script for Notepad++

    这个插件可以方便得让您在Notepad++编辑器中编辑和执行C#代码(脚本).它具备通用的C#智能感知和项目任务管理功能,方式非常类似于MS Visual Studio.除了这一点,它提供了通用的调试 ...

  9. Python模拟登录wap版百度贴吧+自己主动回贴

    模拟登录的原理都差点儿相同.大致都是这样: 打开首页获取相关cookie: 提交登陆表单(即username与password). 确认是否登录成功. 假设想了解更具体的原理与相关知识,推荐到具体解释 ...

  10. 更改Apache的首页

    本机Apache的安装过程请见: Apache的首页是由/usr/local/httpd/conf/httpd.conf文件的DocumentRoot决定的. ...## DocumentRoot: ...