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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

For any even number n greater than or equal to 4, there exists at least one pair of prime numbers?p1?and?p2?such that

n?=?p1?+?p2

This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.

A sequence of even numbers is given as input. There can be many such numbers. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are interested in the number of essentially different pairs and therefore you should not count (p1,?p2) and (p2,?p1) separately as two different pairs.

Input

An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 215. The end of the input is indicated by a number 0.

Output

Each output line should contain an integer number. No other characters should appear in the output.

Sample Input

6 10 12 0

Sample Output

1 2 1

題目大意:

對于任何大于或等于4的偶數n,存在至少一對素數p1和p2,使得n = p1 + p2。我們認為(p1,p2)和(p2,p1)是相同的。問有多少對。。

解題報告:

? 像這種無序的二元組或者無序的三元組啥的,,,為了保證無序,其實只需要滿足他是一個遞增的就可以了。,就像那道 數的劃分? , 一樣。寫dfs的條件就是是遞增的然后去dfs。

AC代碼:

#include<cstdio> #include<cstring> #include<iostream> #define MAX 50001//求MAX范圍內的素數 using namespace std; long long su[MAX],cnt; bool isprime[MAX]; void prime() { cnt=1; memset(isprime,1,sizeof(isprime)); isprime[0]=isprime[1]=0;for(long long i=2;i<=MAX;i++) { if(isprime[i]) {su[cnt++]=i; } for(long long j=1;j<cnt&&su[j]*i<MAX;j++) { isprime[su[j]*i]=0;} } } int main() {prime();int n;int i,ans = 0; while(scanf("%d",&n) && n ) {ans = 0;for( i= 3; i+i<=n; i+=2) {if(isprime[ i ] == 1 && isprime[n-i] == 1) {ans++;}}printf("%d\n",ans);}return 0 ;}

?

總結

以上是生活随笔為你收集整理的【POJ - 2909 】Goldbach's Conjecture (哥德巴赫猜想,数论,知识点结论)的全部內容,希望文章能夠幫你解決所遇到的問題。

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