uva1210

Posted yijiull

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uva1210相关的知识,希望对你有一定的参考价值。

题目连接:UVA - 1210

 1 #include<cstdio>
 2 #include<cmath>
 3 const int maxn=10010;
 4 int pri[maxn];
 5 int ispri[maxn];
 6 int sum[maxn];
 7 int cnt;
 8 void init()
 9 {
10     cnt=1;
11     int m=sqrt(maxn+0.5);
12     for(int i=2;i<=m;i++) if(!ispri[i])
13         for(int j=i*i;j<=maxn;j+=i)
14         ispri[j]=1;
15         for(int i=2;i<=maxn;i++)
16             if(!ispri[i]) pri[cnt++]=i;
17 
18 }
19 
20 int main()
21 {
22     int n;
23     init();
24 
25     for(int i=1;i<cnt;i++)
26         sum[i]=sum[i-1]+pri[i];
27 
28     while(scanf("%d",&n)&&n)
29     {
30         int ans=0;
31         for(int i=1;i<=cnt;i++)
32         {
33             int temp=sum[i]-n;
34             for(int j=0;j<=i;j++)
35                 if(sum[j]==temp) ans++;
36         }
37         printf("%d\n",ans);
38     }
39 }

以上是关于uva1210的主要内容,如果未能解决你的问题,请参考以下文章

UVA1210(连续素数和)。

[UVa1210]Sum of Consecutive Prime Numbers(前缀和,打表)

UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)

Android - 片段中的 getIntent()

在单个活动中动态实现多个片段

UVa 1442 - Cave