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 ;
}

最新文章

  1. 解析大型.NET ERP系统 多国语言实现
  2. JavaScript:最烂与最火
  3. WebApi 登录身份验证
  4. Performance Counter的使用——获取各类组件性能,获取CPU参数等
  5. POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)
  6. Java遇见HTML——JSP篇之JSP状态管理
  7. hdu 1905 小数化分数2
  8. JSP include HTML出现乱码
  9. C++资源之不完全导引 (转载)
  10. ztree树形插件
  11. 【Excel】获取网页标题的VBA
  12. js模块化加载器实现
  13. CentOS6.4下邮件服务器搭建
  14. day27-反射
  15. VisualVM + BTrace
  16. Centos下命令行编译MapReduce代码(Java)并打包在Hadoop中执行
  17. css布局 - 九宫格布局的方法汇总(更新中...)
  18. 20145225唐振远《网络对抗》 Web安全基础实践
  19. bzoj1193 马步距离
  20. Linux 配置TomCat 项目三大步骤

热门文章

  1. X5学习笔记—给单元格添加颜色
  2. 使用AJAX做关键字查询:输入框变化自动搜索、无刷新页面;
  3. nRF51822之模拟IIC
  4. Popwindow自定义动画(nexus5不支持暂未解决)
  5. [LeetCode]题解(python):050-Pow(x, n)
  6. Android笔记:百度地图与高德地图坐标转换问题
  7. JMeter学习-011-JMeter 后置处理器实例之 - 正则表达式提取器(三)多参数获取进阶引用篇
  8. 我的工具箱之VNC
  9. 实践JAVA wait(), notify(),sleep方法--一道多线程的面试题
  10. How to delete expired archive log files using rman?