【POJ】2739
来源:互联网 发布:南平seo快速优化软件 编辑:程序博客网 时间:2024/06/05 20:44
http://poj.org/problem?id=2739
将整数n分解为连续素数之和,有多少种分法?
艾氏筛法做一份素数表,然后在表上爬行一遍。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <algorithm>using namespace std;int n;vector <int> prime;bool is[100005];int ans;void init(){ memset(is,1,sizeof(is)); is[0]=is[1]=false; for (int i=2;i<100005;i++){ if (is[i]){ prime.push_back(i); for (int j=i*2;j<=100005;j+=i){ is[j]=false; } } }}int main(){ init(); int size=prime.size(); while (cin >> n && n){ int l=0,r=0,sum=0,ans=0; while (1){ while (sum<n&&r<size){ sum+=prime[r++]; } if (sum<n){ break; } else if (sum==n){ ans++; } sum-=prime[l++]; } cout << ans << endl; }}
阅读全文
0 0
- POJ 2739
- poj 2739
- poj 2739
- POJ 2739
- POJ 2739
- poj-2739
- POJ 2739
- poj 2739
- poj 2739
- POJ 2739
- POJ 2739
- poj 2739
- Poj 2739
- POJ 2739
- POJ 2739
- POJ 2739
- poj 2739
- 【POJ】2739
- SVM入门(1)--优化目标函数的来龙去脉
- 企业实训day 1
- Spring 框架学习 —— 容器
- Android——AndroidStudio主题样式、字体设置
- WebView的使用
- 【POJ】2739
- 工作中的一些结论
- 归一化
- div 中各种边框
- HDU 3820 Golden Eggs(最大独立集)
- UVa-101 The Blocks Problem(栈模拟)
- Windows下Eclispe远程开发Mapreduce程序
- SSH协议(1)-工作原理及过程
- 发布项目到中央库的一些常见问题