uva1210
来源:互联网 发布:java printf居中 编辑:程序博客网 时间:2024/06/14 05:09
// UVA1210#include <iostream>#include <vector>typedef long long ll;typedef unsigned long long llu;using namespace std;vector<int> prime;const int maxn=10000+10;void init(){ int num[maxn]={0}; for(int i=2; i*i<maxn; i++) for(int j=i*i; j<maxn; j+=i) num[j]=1; for(int i=2; i<maxn; i++) if(!num[i]) prime.push_back(i);}int main(){ init(); int x; while(cin>>x , x) { int l=0, r=0, sum=prime[0]; int ans=0; while(l<=r && prime[r]<=x && r<prime.size()) { if(sum==x) ans++; if(sum>=x) sum-=prime[l++]; else sum+=prime[++r]; } cout<<ans<<endl; } return 0;}
0 0
- uva1210
- uva1210
- UVa1210 Sum of Consecutive Prime Numbers
- UVa1210 - Sum of Consecutive Prime Numbers
- 习题10-6 连续素数之和 UVa1210
- UVa1210 - Sum of Consecutive Prime Numbers(欧拉筛法即线性筛法)
- UVALive3399 UVA1210 POJ2739 Sum of Consecutive Prime Numbers【素数筛选+尺取法】
- C# UdpClient使用Receive和BeginReceive接收消息时的不同写法
- iOS-NSLayoutConstraint-代码实现自动布局的函数用法说明
- python学习之--配置Sublime Text2的python运行环境
- 双连通分量求解===
- 单例模式及C++实现代码
- uva1210
- 【转】机器学习中距离和相似性度量方法
- BuildConfig 无法得到正确创建 (Gradle Android)
- JAVA学习笔记(三) - 选择语句
- 【IOS网络编程】socket编程 - Asyncsocket
- DWR(AJAX)+Highcharts绘制曲线图,饼图
- linux服务器查看日志less命令
- hdu1312Red and Black
- 编程学习网站 收集于网络