UVA 1210(p343)----Sum of Consecutive Prime Numbers
来源:互联网 发布:机锋网推荐的淘宝商家 编辑:程序博客网 时间:2024/05/25 23:27
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=10000;int num,u[maxn+50],prime[maxn+50];int a[6000000],sum[maxn];void get(){ num=1; memset(u,true,sizeof(u)); memset(sum,0,sizeof(sum)); for(int i=2;i<maxn;i++) { if(u[i]) prime[num++]=i; for(int j=1;j<num;j++) { if(i*prime[j]>maxn) break; u[i*prime[j]]=false; if(i%prime[j]==0) break; } } for(int i=1;i<num;i++) sum[i]=sum[i-1]+prime[i];}void solve(){ int temp=0; for(int i=1;i<num;i++) for(int j=i;j<num;j++) a[sum[j]-sum[i-1]]++;}int main(){ //freopen("in.in","r",stdin); //freopen("out.out","w",stdout); get(); solve(); int x; while(scanf("%d",&x)!=EOF&&x) printf("%d\n",a[x]); return 0;}
0 0
- UVA 1210(p343)----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
- Uva-1210 Sum of Consecutive Prime Numbers
- UVa 1210 - Sum of Consecutive Prime Numbers
- UVA - 1210 - Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers UVA
- Sum of Consecutive Prime Numbers UVA
- Sum of Consecutive Prime Numbers UVA
- Sum of Consecutive Prime Numbers - UVa 1210 水题
- UVa 1210 - Sum of Consecutive Prime Numbers(滑动窗口)
- UVA 1210 Sum of Consecutive Prime Numbers(数论)
- UVA 1210 Sum of Consecutive Prime Numbers(素数打表)
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- Sum of Consecutive Prime Numbers
- VMware下对Ubuntu进行扩充磁盘大小
- HTML select option基础理解及使用
- CodeForces 629E(#343)|Famil Door and Roads|树形dp|概率
- nginx-rtmp-module和ffmpeg搭建流媒体服务器
- Cpp_构造函数
- UVA 1210(p343)----Sum of Consecutive Prime Numbers
- PAT (Basic Level) Practise 1002. 写出这个数
- Qt键盘事件
- Eclipse安装SVN教程
- Servlet_04_GenericServlet
- UVA 1213(p343)----Sum of Different Primes
- 关于Assets资源目录结构管理
- Qt中的焦点事件
- Qt::FocusPolicy的使用