hdu 5104 Primes Problem
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=5104
Primes Problem
Description
Given a number n, please count how many tuple$(p_1, p_2, p_3)$ satisfied that $p_1 \leq p_2 \leq p_3, $ $p_1,p_2,p_3$ are primes and $p_1 + p_2 + p_3 = n$.
Input
Multiple test cases(less than 100), for each test case, the only line indicates the positive integer $n\ (n \leq 10000).$
Output
For each test case, print the number of ways.
Sample Input
3
9
Sample Output
0
2
简单题如下。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
using std::cin;
using std::cout;
using std::endl;
using std::find;
using std::sort;
using std::set;
using std::map;
using std::pair;
using std::vector;
using std::multiset;
using std::multimap;
#define pb(e) push_back(e)
#define sz(c) (int)(c).size()
#define mp(a, b) make_pair(a, b)
#define all(c) (c).begin(), (c).end()
#define iter(c) decltype((c).begin())
#define cls(arr,val) memset(arr,val,sizeof(arr))
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
const int N = ;
typedef unsigned long long ull;
bool P[N];
int tot, prime[];
bool isPrim(int n) {
for (int i = ; i * i <= n; i++) if (n % i == ) return false;
return n != ;
}
inline void init() {
for (int i = ; i < N;i++) {
if (isPrim(i)) prime[tot++] = i, P[i] = true;
else P[i] = false;
}
}
inline void solve(int n) {
int res = ;
for (int i = ; i < tot && prime[i] < n; i++) {
for (int j = i; j < tot && prime[j] < n; j++) {
int t = n - prime[i] - prime[j];
if (t >= prime[j] && P[t]) res++;
}
}
printf("%d\n", res);
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n;
init();
while (~scanf("%d", &n)) {
solve(n);
}
return ;
}
hdu 5104 Primes Problem的更多相关文章
- hdu 5104 Primes Problem(prime 将三重循环化两重)
//宁用大量的二维不用量小的三维 #include <iostream> #include<cstdio> #include<cstring> using name ...
- hdu_5104 Primes Problem()
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5104 rimes Problem Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- hdu 5104(数学)
Primes Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)
题目链接: Hdu 5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...
- 网络流 HDU 3549 Flow Problem
网络流 HDU 3549 Flow Problem 题目:pid=3549">http://acm.hdu.edu.cn/showproblem.php?pid=3549 用增广路算法 ...
随机推荐
- Oracle 查看表空间剩余与创建空间语法
select a.tablespace_name,total,free,total-free used from ( select tablespace_name,sum(bytes)/1024/10 ...
- 用 vs2013 创建 windows service 程序
windows services 是运行在后台的服务程序,可以用 vs2013 来创建,创建的步骤如下: 1.打开 vs2013 , Files -->New Project --> wi ...
- gulp&gulp-less
使用gulp-less插件将less文件编译成css,当有less文件发生改变自动编译less,并保证less语法错误或出现异常时能正常工作并提示错误信息. 1.本地安装gulp-less githu ...
- ruby中symbol
Symbol 是什么 Ruby 是一个强大的面向对象脚本语言(本文所用 Ruby 版本为1.8.6),在 Ruby 中 Symbol 表示“名字”,比如字符串的名字,标识符的名字. 创建一个 Symb ...
- leetcode 121
121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of ...
- leetcode 110
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, ...
- poj2017
一天两个题,凑数用的大水题啊...不解释了..羞愧ing #include <stdio.h> int main(){ int t; int i; ],b[],tot; ){ tot=; ...
- Nginx 下无法读取session 导致 thinkphp验证码错误
打开php配置文件 php.ini 使用搜索命令 whereis php.ini 一般在:/etc/php.ini 目录下 使用vim命令打开 找到: session.save_path 找到php保 ...
- TCP/UDP详解
转载:http://www.cnblogs.com/visily/archive/2013/03/15/2961190.html, 作者:望梅止渴 相关: HTTP协议详解 深入理解HTTP协议 T ...
- CTest
一.初识CTest CTest是CMake集成的一个测试工具,在使用CMakeLists.txt文件编译工程的时候,CTest会自动configure.build.test和展现测试结果 CTest有 ...