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. LXT技术平台(Lenovo Trust Technology)

    LXT技术平台(L是Lenovo的缩写,T是技术Technology,X代表多个应用方向),是联想以用户需求为导向,整合先进技术,为用户提供最佳应用体验的一体化解决方案. 中文:LXT技术平台 外文: ...

  2. 第三章 JVM内存回收区域+对象存活的判断+引用类型+垃圾回收线程

    注意:本文主要参考自<深入理解Java虚拟机(第二版)> 说明:查看本文之前,推荐先知道JVM内存结构,见<第一章 JVM内存结构> 1.内存回收的区域 堆:这是GC的主要区域 ...

  3. 使用FlexiGrid实现Extjs表格的效果-网络传输小,更方便!

      近一段时间Extjs真的是风光无限好,只要是个做CRM/HRM之类的企业现在都在琢磨怎么在项目中用它,不过兄弟我可是不敢,原因很简单:太大/太笨/源码不好调试.但是对于Extjs漂亮的表格与功能的 ...

  4. Spark Streaming事务处理彻底掌握

    本篇文章主要从二个方面展开: 一.Exactly Once 二.输出不重复 事务: 银行转帐为例,A用户转账给B用户,B用户可能收到多笔钱,如何保证事务的一致性,也就是说事务输出,能够输出且只会输出一 ...

  5. (转)<Unity3D>Unity3D在android下调试

    转自:http://blog.csdn.net/zuoyamin/article/details/11827309 一.工具准备 1.JDK——由于android是基于Java平台开发的,jdk是必须 ...

  6. Hibernate常用查询语句

    Hibernate常用查询语句 Hib的检索方式1'导航对象图检索方式.通过已经加载的对象,调用.iterator()方法可以得到order对象如果是首次执行此方法,Hib会从数据库加载关联的orde ...

  7. ZH奶酪:Linux新建用户+远程登录

    7.想在VBUbuntu中新建一个账户,但是用useradd命令发现没有权限,原来Ubuntu默认不是root权限登录,需要按照下边的教程才能新建用户. http://www.linuxidc.com ...

  8. redis 安装 命令

    安装: http://redis.io/download 在线操作命令:http://try.redis.io/ 命令查询:https://redis.readthedocs.org/en/lates ...

  9. VIM经常使用操作

    VIM使用 移动命令 按键 说明 h 左 l 右(小写L) j 下 k 上 w 移动到下一个单词 b 移动到上一个单词 进入插入模式 命令 说明 i 在当前光标处进行编辑 I 在行首插入 A 在行末插 ...

  10. svn log笔记

    背景: svn,版本 1.7.8 以下所有命令直接和svn服务器进行交互并没有checkout代码到本地 1.查询分支从拉出来到现在的变更: svn log branche_url --stop-on ...