http://acm.hdu.edu.cn/showproblem.php?pid=4715

Difference Between Primes

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

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 x at the next n lines. The absolute value of x is not greater than 10^6.
 
Output
For each number x tested, outputs two primes a and b at one line separated with 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

分析:

这道题就是求一个整数用两个素数(大于等于2)的差表示出来,要求两个素数在满足条件的情况下最小。

AC代码:

 #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma warning(disable:4786) using namespace std; const int INF = 0x3f3f3f3f;
const int MAX = + ;
const double eps = 1e-;
const double PI = acos(-1.0); int a[MAX]; int main()
{
int i , j ;
memset(a , , sizeof(a));
a[] = ; a[] = ;
for(i = ;i <= sqrt(MAX);i++)
{
if(a[i] == )
for(j = i * i;j <= MAX;j += i)
a[j] = ;
}
int n,m;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
int t = abs(m);
for(i = t;i < MAX;i++)
if(!a[i] && !a[i - t])
{
if(m > )
{
printf("%d %d\n",i,i - t);
break;
}
else
{
printf("%d %d\n",i - t,i);
break;
}
}
if(i == MAX)
printf("FAIL\n");
}
return ;
}

hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup的更多相关文章

  1. hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...

  2. hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup

    hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...

  3. hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...

  4. hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...

  5. hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  6. hduoj 4706 Children&#39;s Day 2013 ACM/ICPC Asia Regional Online —— Warmup

    http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...

  7. 2013 ACM/ICPC Asia Regional Online —— Warmup

    1003 Rotation Lock Puzzle 找出每一圈中的最大值即可 代码如下: #include<iostream> #include<stdio.h> #inclu ...

  8. HDU 4714 Tree2cycle(树状DP)(2013 ACM/ICPC Asia Regional Online ―― Warmup)

    Description A tree with N nodes and N-1 edges is given. To connect or disconnect one edge, we need 1 ...

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

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

随机推荐

  1. Apache Kafka源码分析 - PartitionStateMachine

    startup 在onControllerFailover中被调用, initializePartitionState private def initializePartitionState() { ...

  2. JAVA基础讲义

    一.安装JDK 第一步:双击JDK的exe文件. JDK(Java开发包),JRE(Java运行环境) 第二步:配置 path:jdk的根目录,jdk下的bin目录(两个目录之间记得用分号隔开) cl ...

  3. 关于优化sql查询的一个方法。

    select * from gmvcsbase.base_file file,gmvcsbase.base_user user,gmvcsbase.base_department dep,gmvcsb ...

  4. myeclipse 8.5 常用快捷键【转】

    eclipse 里查找行号的方法 今天开发的时候为了方便查找报错行的位置,特意在网上找了一下快捷键是什么,现做记录. 在Eclipse里的show the line number 后,使用" ...

  5. spring环境的搭建及作用和定义<一>

    问题?spring的定义及作用.spring的环境搭建 一.spring的定义及作用 1.spring由Rod Johnson创建的一个开源框架,它是为了解决企业应用开发的复杂性而创建的.框架的主要优 ...

  6. LMAO?

    70 weeks to finish TC problems? 2015.4.16 week1 week1~week8:Graph 1.DFS,BFS,Topological sort,Strongl ...

  7. install zabbix-agent on CENTOS

    in ubuntu--https://www.digitalocean.com/community/tutorials/how-to-install-zabbix-on-ubuntu-configur ...

  8. js解析Json字符串的方法

      要把一个xml字符串转(“1,2,3,4,5,6,7,8,1,2”)换成数组的形式,每个值都应该是number类型的,想当然的就用了split方法,结果...问题来了,服务器要求数组的值是数字,而 ...

  9. 自动将每日的日志增量导入到hive中

    一:大纲介绍 1.导入方式 load data local inpath 'local_file_path' into table tbname partition (date='',hour='') ...

  10. Android开发笔记:eclipse导入java项目

    若下载的工程文件中含有 .project 则点击菜单栏file-import,选择General-existing project into workplace,点击下一步 选择需要导入的项目文件夹