日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Sum of Consecutive Prime Numbers POJ - 2739(线性欧拉筛+尺取法)

發布時間:2023/12/4 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Sum of Consecutive Prime Numbers POJ - 2739(线性欧拉筛+尺取法) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:

一些正整數可以由一個或多個連續質數的總和表示。給定一個的正整數n,問滿足條件的有多少種情況?

題目:

Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2+3+5+7+11+13, 11+13+17, and 41. The integer 3 has only one representation, which is 3. The integer 20 has no such representations. Note that summands must be consecutive prime
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.

Input

The input is a sequence of positive integers each in a separate line. The integers are between 2 and 10 000, inclusive. The end of the input is indicated by a zero.

Output

The output should be composed of lines each corresponding to an input line except the last zero. An output line includes the number of representations for the input integer as the sum of one or more consecutive prime numbers. No other characters should be inserted in the output.

Sample Input

2
3
17
41
20
666
12
53
0

Sample Output

1
1
2
3
0
0
1
2

分析:

1.將 2 至 10000 內的素數存入一個數組;
2.對于每一個給定的數,從左向右遍歷數組,根據連續素數的和的大小不斷的增減元素,直到找到一個個解。

AC模板:

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int M=1e4+10; int n,k,r,l,ans,mi; int dp[M],book[M]; void init() {k=0;/** for(int i=2; i<M; i++){if(!book[i]){dp[k++]=i;for(int j=i*2; j<M; j+=i)book[j]=1;}}*/for(int i=2;i<M;i++){if(!book[i])dp[k++]=i;for(int j=0;j<k&&i*dp[j]<M;j++){book[i*dp[j]]=1;if(i%dp[j]==0)break;}}} int solve(int x) {ans=0;for(int i=0; i<k&&dp[i]<=x; i++){l=i,mi=0;while(mi<x&&l<k){mi+=dp[l++];}if(mi==x)ans++;}return ans; } int main() {init();while(~scanf("%d",&n)&&n){printf("%d\n",solve(n));}return 0; }

備戰ccpc分站賽ing ,題目分析簡略,見諒,轉載請注明出處。。。。。

總結

以上是生活随笔為你收集整理的Sum of Consecutive Prime Numbers POJ - 2739(线性欧拉筛+尺取法)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久久久久久久久久久久久 | 69av国产| 欧美少妇一区二区 | 51成人网| 一级特毛片 | 亚洲精品一二三四 | 精品一区二区三区免费毛片 | 久久久精品国产 | 黄色观看网站 | 舔花蒂 | 黄色片网站在线播放 | 九九在线| 日日草| 色视频2 | 欧洲一区二区视频 | 亚洲淫欲 | 日本少妇做爰全过程毛片 | 丰满少妇一级 | 咪咪色在线视频 | 小镇姑娘高清播放视频 | 一本久久久久 | 黄色图片小说 | 精品欧美一区二区久久久久 | 超碰caopeng | 五月天综合激情网 | 97欧美视频 | 蜜桃成人在线视频 | 日韩欧美中文在线 | 99精品欧美一区二区三区综合在线 | 进去里视频在线观看 | 欧洲综合色 | 国产精品91一区 | 午夜电影一区二区 | 91大尺度 | 国产探花精品一区二区 | 国产传媒中文字幕 | 国产精品久久久久久久久 | 91精彩刺激对白 | 毛片h| 图片区视频区小说区 | 欧美xxxx日本和非洲 | 亚洲最大的成人网站 | 国产无遮挡又黄又爽免费网站 | 久久综合色88 | 青青草视频偷拍 | 成人片在线播放 | 美女被草网站 | 深夜网站在线观看 | 五月婷婷影院 | 国产精品乱子伦 | 久操青青 | 一眉道姑| 日韩精品视频网 | 精品国产乱码久久久久 | jzzjzzjzz亚洲成熟少妇 | 麻豆视频国产 | 美女考逼| 欧美一级做性受免费大片免费 | 久操资源网| 91丝袜国产在线播放 | 永久免费,视频 | 在线欧美视频 | 中文字幕在线2018 | 东北少妇不戴套对白第一次 | 嫩草一区二区 | 亚洲精品一区二区三区四区 | 成人午夜精品一区二区三区 | 性生活毛片 | 久久狠狠婷婷 | 精品五月天 | 草久在线观看视频 | 精品久久久久国产 | 看免费黄色大片 | 欧美日韩中文字幕在线视频 | 色88久久久久高潮综合影院 | jlzzjlzz亚洲女人 | 天天操人人干 | 成人91免费 | 不卡av网 | 久久国产人妻一区二区免色戒电影 | 日韩欧美成人网 | 久久国产精品综合 | 国产调教视频在线观看 | 欧美视频在线不卡 | 91久色视频 | 国产色片| 在线不卡欧美 | 国产一及毛片 | 日本一区二区三区久久久久 | 成人性色生活片 | 一区二区韩国 | 91欧美国产| 办公室摸腿吻胸激情视频 | 麻豆国产尤物av尤物在线观看 | 中日韩午夜理伦电影免费 | 特大黑人娇小亚洲女mp4 | 欧美性猛交xxxx乱 | 国产激情综合五月久久 | 国产日韩在线免费观看 |