HDU 5104 Primes Problem(素数打表)
来源:互联网 发布:java运行环境官方下载 编辑:程序博客网 时间:2024/05/21 08:49
Primes Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3614 Accepted Submission(s): 1629
Problem Description
Given a number n, please count how many tuple(p1, p2, p3) satisfied that p1<=p2<=p3, p1,p2,p3 are primes and p1 + p2 + p3 = n.
Input
Multiple test cases(less than 100), for each test case, the only line indicates the positive integer n(n≤10000).
Output
For each test case, print the number of ways.
Sample Input39Sample Output02
题目不难,就是先打表在暴力,直接暴力不用想肯定超。
#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespace std;int pr[10010],bo[100000]={0};int num=0;void primes(){ for (int i=2;i<=10000;i++) { if(!bo[i]) pr[++num]=i; for (int j=1;j<=num && pr[j]*i<=10000;j++) { bo[i*pr[j]]=1; if(i%pr[j]==0)break; } }}int main(){ primes(); int k,n,m,sum; while(scanf("%d",&k)!=EOF) { sum=0; for(int i=1;pr[i]<=k;i++) { for(int j=i;pr[j]<=k;j++) { if(!bo[k-pr[i]-pr[j]]&&(k-pr[i]-pr[j])>=pr[j]) sum++; } } printf("%d\n",sum); } return 0;}
阅读全文
0 0
- HDU 5104 Primes Problem(素数打表)
- HDU 5104 Primes Problem(打表)
- hdoj--5104--Primes Problem(素数打表)
- hdoj Primes Problem 5104 (素数打表&&技巧)
- hdoj-5104Primes Problem(素数打表)
- HDU 2161 Primes(素数打表)
- hdu 5104 Primes Problem(素数判定)
- hdu 2161 Primes 素数打表
- HDOJ(HDU) 2161 Primes(素数打表)
- Primes Problem HDU 5104 打表大法好啊~~
- hdu 2161 Primes(数学:素数打表+水题)
- HDU Prime Ring Problem (DFS+素数打表)
- HDU 5104 Primes Problem
- HDU 5104 Primes Problem
- hdu 5104 Primes Problem
- HDU-#5104 Primes Problem
- HDU 5104 Primes Problem
- hdu 5104 Primes Problem
- 原型模式(C++)
- 数组相减java
- 分类模型与算法--决策树
- TensorFlow学习笔记4:logistic回归
- MAC 解决OSError: [Errno 1] Operation not permitted
- HDU 5104 Primes Problem(素数打表)
- LeetCode算法题——Top K Frequent Words
- JS实现找第n个丑数(动态规划)
- ajax请求https
- LDA
- 参考文献格式生成器
- Spring Boot + Dubbo + Zookeeper 分布式架构
- 素数打表模板
- 大型网站架构演变和知识体系