hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
2024-10-15 22:38:00
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 ;
}
最新文章
- 解析大型.NET ERP系统 多国语言实现
- JavaScript:最烂与最火
- WebApi 登录身份验证
- Performance Counter的使用——获取各类组件性能,获取CPU参数等
- POJ 3321 Apple Tree(DFS序+线段树单点修改区间查询)
- Java遇见HTML——JSP篇之JSP状态管理
- hdu 1905 小数化分数2
- JSP include HTML出现乱码
- C++资源之不完全导引 (转载)
- ztree树形插件
- 【Excel】获取网页标题的VBA
- js模块化加载器实现
- CentOS6.4下邮件服务器搭建
- day27-反射
- VisualVM + BTrace
- Centos下命令行编译MapReduce代码(Java)并打包在Hadoop中执行
- css布局 - 九宫格布局的方法汇总(更新中...)
- 20145225唐振远《网络对抗》 Web安全基础实践
- bzoj1193 马步距离
- Linux 配置TomCat 项目三大步骤
热门文章
- X5学习笔记—给单元格添加颜色
- 使用AJAX做关键字查询:输入框变化自动搜索、无刷新页面;
- nRF51822之模拟IIC
- Popwindow自定义动画(nexus5不支持暂未解决)
- [LeetCode]题解(python):050-Pow(x, n)
- Android笔记:百度地图与高德地图坐标转换问题
- JMeter学习-011-JMeter 后置处理器实例之 - 正则表达式提取器(三)多参数获取进阶引用篇
- 我的工具箱之VNC
- 实践JAVA wait(), notify(),sleep方法--一道多线程的面试题
- How to delete expired archive log files using rman?