HDU 5104 Primes Problem(打表)
来源:互联网 发布:medline数据库论文 编辑:程序博客网 时间:2024/06/05 19:03
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=5104
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
3
9
Sample Output
0
2
把我wa哭了 判断结果那 写成prime[j]&&prime[i] 就时间超限
prime[i]&&prime[j] 就过了 不是很懂
code:
#include<cstdio>#include<iostream>//#include<bits/stdc++.h>#include <string.h>using namespace std;int is_prime(int n ){ for(int i=2 ;i*i<=n;i++ ) { if ( n % i ==0) return 0; } return 1;}int main(){ int prime[10005]; memset(prime, 0 ,sizeof(prime));// for (int i=2; i<=10002; i++)// {// int flag=0;// for (int j=2; j*j<=i;j++)// {// if (i%j==0)// {// flag=1;// break;// }//// }// if (flag==0)// prime[i]=1;//// }for(int i=2 ;i<=10002;i++) { if ( is_prime(i) ) prime[i] = 1; } int n; while (cin>>n) { int num=0; for (int i=2; i<=n; i++) { for (int j=i; j<=(n-i)/2; j++) { if (prime[i]&&prime[j]&&prime[n-i-j]) { num++; } } } cout<<num<<endl; } return 0;}
阅读全文
0 0
- HDU 5104 Primes Problem(打表)
- HDU 5104 Primes Problem(素数打表)
- Primes Problem HDU 5104 打表大法好啊~~
- hdoj Primes Problem 5104 (素数打表&&技巧)
- hdoj-5104Primes Problem(素数打表)
- hdoj--5104--Primes Problem(素数打表)
- HDU 2161 Primes(素数打表)
- 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(数学)
- 机器学习中的最优化方法进阶
- make之学习笔记
- 搭建第一个scrapy项目的常见问题
- 理解Android Service
- java多线程之线程的安全性(一)
- HDU 5104 Primes Problem(打表)
- 【NOIP2013模拟联考7】最长上升子序列
- Qt学习之路——Qt简介
- Android编译系统
- Ubuntu安装NVIDIA驱动后桌面循环登录
- 深度学习之图像分割 《Fully Convolutional Networks for Semantic Segmentation》—FCN
- Java包(package)命名规则
- centos7下NAT模式设置静态ip
- Linux C 多人网络聊天室(UDP)