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. oracle communities

    应该常来这看看 https://www.oracle.com/communities/index.html

  2. [have_fun] 好玩哒小游戏

    好玩哒,打字小游戏:http://zty.pe/ 可好玩了,一起来玩吧!

  3. transform animation transition css3动画

    transform 定义   transform 属性向元素应用 2D 或 3D 转换.该属性允许我们对元素进行旋转.缩放.移动或倾斜. 值 应用  如果transform与transition联合起 ...

  4. Windows系统结合MinGW搭建软件开发环境

    MinGW介绍 MinGW,即Minimalist GNU For Windows,它包含了GNU工具集的运行环境.GCC编译器工具集以及其它的GNU程序开发工具(如make.gawk.grep等等) ...

  5. Linux QtCreator设置mingw编译器生成windows程序

    Qt跨平台,那必须在Linux平台编译一个可以在windows下运行的Qt程序才行,当然还得和QtCreator环境弄在一起才行. 工作环境:Centos 7 yum install qt5-qt* ...

  6. 【Android测试】【第六节】Monkey——认识和使用

    ◆版权声明:本文出自carter_dream的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4688880.html 自动化工具 接触安 ...

  7. 深入理解Linux中内存管理

    前一段时间看了<深入理解Linux内核>对其中的内存管理部分花了不少时间,但是还是有很多问题不是很清楚,最近又花了一些时间复习了一下,在这里记录下自己的理解和对Linux中内存管理的一些看 ...

  8. NSNotificationCenter带参

    (1)post Notification类 [[NSNotificationCenter defaultCenter] postNotificationName:CRMPerformanceNewCe ...

  9. Selenium2学习-005-WebUI自动化实战实例-003-三种浏览器(Chrome、Firefox、IE)启动脚本源代码

    此文主要通过 三种浏览器(Chrome.Firefox.IE)启动脚本 功能,进行 Selenium2 三种浏览器启动方法的实战实例讲解.文中所附源代码于 2015-01-18 20:33 亲测通过, ...

  10. iOS:app直播---采集篇

    [如何快速的开发一个完整的iOS直播app](采集篇) 转载自简书@袁峥Seemygo:http://www.jianshu.com/p/c71bfda055fa 前言 开发一款直播app,首先需要采 ...