HDU 5104 Primes Problem
来源:互联网 发布:2017安全知识网络答题 编辑:程序博客网 时间:2024/06/11 02:40
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104
题面:
Primes Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1776 Accepted Submission(s): 813
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 Input
39
Sample Output
02
Source
BestCoder Round #18
解题:
唉,说好不刷水题的了,又刷,真是不好...
代码:
#include <iostream>#include <cmath>using namespace std;int store_prime[10000],cnt=0;bool is_prime(int x){if(x==2)return true;int up_limit=sqrt(1.0*x);for(int i=2;i<=up_limit;i++){if(x%i==0)return false;}return true;}int main(){for(int i=2;i<=10000;i++){if(is_prime(i)){store_prime[cnt++]=i;}}int tmp,sum,n,ans;while(cin>>n){ans=0;for(int i=0;i<cnt;i++){for(int j=i;j<cnt;j++){tmp=n-store_prime[i]-store_prime[j];if(tmp>=store_prime[j]&&is_prime(tmp))ans++;}}cout<<ans<<endl;}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 水题
- 在传统以太网中,为什么要有最小帧长度和最大帧长度的限制?
- gcd相关
- #leetcode#Isomorphic Strings
- 如何让超出父视图区域的子视图实现点击事件
- NamedParameterJdbcTemplate的用法
- HDU 5104 Primes Problem
- R in action读书笔记(17)第十二章 重抽样与自助法
- arc的使用
- JDBC(一)
- echarts单击事件
- 北大 oj 1088 滑雪
- NHibernate:一对多,多对一关系映射之修改,删除
- archlinux 解压zip乱码 已解决
- 解决Python2.7的UnicodeEncodeError: 'ascii' codec can't encode异常错误