UVa 1210 - Sum of Consecutive Prime Numbers
2015-03-02 16:40
344 查看
高中数学数列方法做的,打表大法好,全程打表。
计算一段数的和,用S(n~m) = S(m) - S(n-1)做的。
计算一段数的和,用S(n~m) = S(m) - S(n-1)做的。
#include <bits/stdc++.h> using namespace std; const int maxn = 10001; bool isp[maxn]; int cnt, p[2000], sum[2000], res[100000]; void init() { memset(isp, true, sizeof(isp)); isp[0] = isp[1] = false; const int max1 = sqrt(maxn + 0.5); for(int i = 2; i <= max1; i++) if(isp[i]) for(int j = i * i; j < maxn; j += i) isp[j] = false; for(int i = 0; i < maxn; ++i) if(isp[i]) p[++cnt] = i; for(int i = 1; i <= cnt; ++i) sum[i] = sum[i-1] + p[i]; for(int i = 1; i <= cnt; ++i) for(int j = i; j <= cnt; ++j) if(sum[j]-sum[i-1] <= 10000) ++res[sum[j]-sum[i-1]]; } int main () { init(); int n; while(cin >> n, n) cout << res << endl; return 0; }
相关文章推荐
- UVA 1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(素数打表)
- UVa1210 Sum of Consecutive Prime Numbers
- UVA 1210 Sum of Consecutive Prime Numbers(数论)
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVALive3399 UVA1210 POJ2739 Sum of Consecutive Prime Numbers【素数筛选+尺取法】
- UVa 1210 - Sum of Consecutive Prime Numbers(素数+连续和)
- Sum of Consecutive Prime Numbers - UVa 1210 水题
- 习题10-6 UVA - 1210 Sum of Consecutive Prime Numbers 连续素数之和(滑动窗口)
- 【UVA】1210 - Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers UVA - 1210 连续素数之和
- Sum of Consecutive Prime Numbers UVA - 1210
- UVA - 1210 - Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers(欧拉筛法即线性筛法)
- [UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)
- UVa 1210 - Sum of Consecutive Prime Numbers(滑动窗口)
- UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
- Uva-1210 Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers