HDU-#5104 Primes Problem
来源:互联网 发布:淘宝网限时秒杀 编辑:程序博客网 时间:2024/06/06 02:18
题目大意:给一个数N,求一个元组(p1,p2,p3),使得三个数都是素数且有序。
解题思路:直接先打素数表,因为数据范围是1e4,因此可以直接暴力求解,枚举前面两个数,然后判断第三个数是否满足条件即可,详见code。
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=5104
code:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;const int MAXN = 10000+100;int isp[MAXN];int n,cnt;void init(){ memset(isp,0,sizeof(isp)); for(int i=2;i<sqrt(MAXN+0.5);++i) for(int j=2;i*j<MAXN;++j) isp[i*j]=1;}int main(){ init(); while(~scanf("%d",&n)){ cnt=0; for(int i=2;i<=n;++i) if(!isp[i]){ for(int j=i;j<=(n-i)/2;++j) if(!isp[j] && !isp[n-i-j]) ++cnt; } printf("%d\n",cnt); } return 0;}
0 0
- HDU 5104 Primes Problem
- HDU 5104 Primes Problem
- hdu 5104 Primes Problem
- HDU-#5104 Primes Problem
- HDU 5104 Primes Problem
- hdu 5104 Primes Problem
- HDU 5104 Primes Problem
- hdu 5104 Primes Problem
- HDU 5104 Primes Problem
- HDU 5104-Primes Problem
- hdu 5104 Primes Problem(数学)
- HDU 5104 - Primes Problem (枚举)
- HDU 5104 Primes Problem(数学)
- hdu 5104 Primes Problem(素数判定)
- HDU 5104 Primes Problem(打表)
- HDU--Primes Problem
- HDOJ 5104 Primes Problem
- HDU 5104 Bestcoder #18 1001 Primes Problem 水题
- 【贪心】HDU-1789 Doing Homework again
- 最新版spark1.1.0集群安装配置
- Session对性能测试的影响
- 【转】PC-Lint的使用方法
- 太恶心了,竟是这个原因导致Android程序UI无法预览
- HDU-#5104 Primes Problem
- ARM寄存器的别名、以及关于APCS
- W3Help知识库(web兼容性问题解决方案知识库)
- 目标识别器的设计-TargetMarker-1
- 图像处理中的卷积与模板
- 第十三周项目字符串操作 字符统计
- sendmessage和postmessage的区别
- 【HTTP】Fiddler(二) - 使用Fiddler做抓包分析
- Humble Numbers数论(HDU 1055)