POJ 2739 解题报告
2014-12-14 08:40
260 查看
这道题也挺简单的。就是素数筛选法先筛选出1000以内的所有素数,然后按照题目描述的统计就好了。
2739 | Accepted | 156K | 0MS | C++ | 1131B |
/* ID: thestor1 LANG: C++ TASK: poj2739 */ #include <iostream> #include <fstream> #include <cmath> #include <cstdio> #include <cstring> #include <limits> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <cassert> using namespace std; const int MAXN = 10000; int main() { std::vector<bool> isprime(MAXN, true); for (int n = 2; n < MAXN; ++n) { if (isprime ) { for (int k = n; n * k < MAXN; ++k) { isprime[n * k] = false; } } } std::vector<int> primes; for (int n = 2; n < MAXN; ++n) { if (isprime ) { primes.push_back(n); } } // for (int i = 0; i < primes.size(); ++i) // { // printf("%d ", primes[i]); // } int n; while (scanf("%d", &n) && n) { int cnt = 0; for (int left = 0; primes[left] <= n; ++left) { int sum = primes[left]; int right = left + 1; while (sum < n) { sum += primes[right]; right++; } cnt += (sum == n); } printf("%d\n", cnt); } return 0; }
相关文章推荐
- POJ2739解题报告
- poj 2739解题报告
- poj2739 解题报告(poj 2739 analysis report)
- 【原】 POJ 2739 Sum of Consecutive Prime Numbers 筛素数+积累数组 解题报告
- POJ 2739(连续素数和) 解题报告
- poj 2739 Sum of Consecutive Prime Numbers 解题报告
- POJ 2739(连续素数和) 解题报告
- LA-3399 & POJ-2739 Sum of Consecutive Prime Numbers 解题报告
- poj2739解题报告
- poj2498解题报告
- POJ 1797 Heavy Transportation(Dijkstra变形) 解题报告
- poj解题报告——1003、1005、1799
- POJ 2942 Tarjan双联通分量+二分图 解题报告
- poj 2449 Remmarguts' Date 第k短路 A*+spfa 解题报告
- POJ-1411 & HDOJ-1239 Calling Extraterrestrial Intelligence Again 解题报告
- POJ - 1442 Black Box解题报告(求第k小的数 堆)
- POJ1068 解题报告
- POJ 2719 Faulty Odometer 解题报告
- POJ - 1195 Mobile phones解题报告(二维树状数组)
- POJ 3278解题报告(C语言版)//Catch That Cow