hdoj-5104Primes Problem(素数打表)
来源:互联网 发布:c语言常用函数 编辑:程序博客网 时间:2024/06/03 12:50
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 Input
39
Sample Output
02
题目链接
这里要注意素数打表和比较的方式,很容易超时。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int num[10005];void prime(){for(int i=2;i<10005;i++){if(num[i]==0){for(int j=i+i;j<10005;j+=i)num[j]=1;}}}int main(){int n;memset(num,0,sizeof(num));num[1]=1;prime();while(scanf("%d",&n)!=EOF){int ans=0;for(int i=2;i<=n;i++){for(int j=i;j<=(n-i)/2;j++){if(!num[j]&&!num[i]&&!num[n-i-j])ans++;}}printf("%d\n",ans);}return 0;}
阅读全文
1 0
- hdoj--5104--Primes Problem(素数打表)
- hdoj Primes Problem 5104 (素数打表&&技巧)
- hdoj-5104Primes Problem(素数打表)
- HDU 5104 Primes Problem(素数打表)
- HDOJ(HDU) 2161 Primes(素数打表)
- HDU 5104 Primes Problem(打表)
- HDU 2161 Primes(素数打表)
- HDOJ 5104 Primes Problem
- hdu 5104 Primes Problem(素数判定)
- Primes on Interval(素数打表+二分)
- HDOJ 5901 Count primes 【2016年沈阳网赛】素数打表
- Primes Problem HDU 5104 打表大法好啊~~
- HDOJ 4548 美素数(打表)
- hdu 2161 Primes 素数打表
- HDOJ 2161 Primes (判断素数)
- HDOJ 2161 Primes【素数】
- hdoj 素数判定 2012 (素数打表)
- HDU5104 Primes Problem(素数筛选法)
- Javascript 数据类型
- SpringMVC的常用注解
- Qt和C语言之间的交互
- 双击dataGridView一行数据,打开一个另一个窗体,并把双击行的数据展示出来
- Java求两个非负整数之间的最大公约数
- hdoj-5104Primes Problem(素数打表)
- jQuery中的队列操作
- 蓝桥杯 算法训练 阶乘
- windows核心编程---内存映射文件
- tcpdump
- Google浏览器在Ubuntu14.04下的安装和配置
- linux下安装JDK
- 第一次写博客,有一些想法
- 数列