POJ-2739Sum of Consecutive Prime Numbers(尺取法+埃拉托斯特尼筛法)
来源:互联网 发布:bl国产网络剧 编辑:程序博客网 时间:2024/05/22 10:58
首先了解 埃拉托斯特尼筛法
参考博客:点击打开链接
看完图解基本就知道埃拉托斯特尼筛法的步骤了
知道了打表然后就是水题了
#include <iostream>#include <map>#include <algorithm>#include <cstdio>#include <cstring>#include <cstdlib>#include <vector>#include <queue>#include <stack>#include <functional>#include <set>#include<sstream>#include <cmath>using namespace std;#define pb push_back#define PB pop_back#define bk back()#define fs first#define se second#define INF 1e10;#define sq(x) (x)*(x)#define eps (1e-10)#define clr(x) memset((x),0,sizeof (x))#define cp(a,b) memcpy((a),(b),sizeof (b))typedef long long ll;typedef unsigned long long ull;typedef pair<int,int> P;const int maxn=10100;int is_prim[maxn];int prim[maxn];int k=1;void get_prim(){ int m=sqrt(maxn)+1; for(int i=2;i<maxn;i++) is_prim[i]=1; for(int i=2;i<m;i++) { if(is_prim[i]) { for(int j=i+i;j<maxn;j+=i) is_prim[j]=0; } }}int main(){ clr(prim); prim[k++]=2; get_prim(); for(int i=3;i<maxn;i++) if(is_prim[i]) prim[k++]=i; k--; int n; while(cin>>n&&n) { int sum=0,len=0,s=1,f=1,cnt=0; for(;;) { while(sum<n&&s<=k) { sum+=prim[s++]; len++; } if(len==0) break; if(sum==n) cnt++; sum-=prim[f++]; len--; } cout<<cnt<<endl; } return 0;}
0 0
- POJ - 2739 Sum of Consecutive Prime Numbers(尺取法)
- poj 2739 Sum of Consecutive Prime Numbers(尺取法)
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
- POJ 2739 Sum of Consecutive Prime Numbers 尺取法
- POJ - 2739 Sum of Consecutive Prime Numbers(尺取法)
- 尺取法入门 POJ 2739 Sum of Consecutive Prime Numbers
- POJ-2739Sum of Consecutive Prime Numbers(尺取法+埃拉托斯特尼筛法)
- POJ 2739 Sum of Consecutive Prime Numbers(素数序列和,尺取法)
- POJ2739---Sum of Consecutive Prime Numbers(尺取法)
- POJ2739--Sum of Consecutive Prime Numbers(尺取法)
- POJ 2739 Sum of Consecutive Prime Numbers 素数打表+尺取法
- POJ 2739 - Sum of Consecutive Prime Numbers(素数筛法+前缀和 / 尺取法)
- Sum of Consecutive Prime Numbers(POJ 2739)尺取法+数学问题
- POJ 2739 E - Sum of Consecutive Prime Numbers 素数打表+尺取法
- POJ 2739 · Sum of Consecutive Prime Numbers【尺取法】【筛法】
- POJ 2739 Sum of Consecutive Prime Numbers(尺取)
- POJ 2739 Sum of Consecutive Prime Numbers(尺取)
- POJ 2739Sum of Consecutive Prime Numbers(尺取)
- zzulioj--1790-- 弹珠游戏(数学水题!)
- 【MySQL入门篇】1.MySQL安装与配置--慕课网【学习总结】
- 607A Chain Reaction(DP)
- POJ-2566Bound Found(尺取法)(好题)
- Java的异常、断言、日志和调试
- POJ-2739Sum of Consecutive Prime Numbers(尺取法+埃拉托斯特尼筛法)
- CentOS 6.5上inotify-tools使用方法
- Android Design Support Library 的 代码实验——几行代码,让你的 APP 变得花俏
- Objective-C语言——单例模式
- android中使用xml里的array资源
- GitHub 使用(Win7 下Git Bash)
- 华为桌面云使user用户具有管理权限的模板封装(链接克隆)
- 数据库的约束
- dyld: Library not loaded: