国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

文章標題

2019-11-08 18:43:26
字體:
來源:轉載
供稿:網友

Goldbach’s conjecture is one of the oldest unsolved PRoblems in number theory and in all of mathematics. It states:

Every even integer, greater than 2, can be expressed as the sum of two primes [1].

Now your task is to check whether this conjecture holds for integers up to 107.

Input

Input starts with an integer T (≤ 300), denoting the number of test cases.

Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).

Output

For each case, print the case number and the number of ways you can express n as sum of two primes. To be more specific, we want to find the number of (a, b) where

1) Both a and b are prime 2) a + b = n 3) a ≤ b

Sample Input

2 6 4

Sample Output

Case 1: 1 Case 2: 1

Hint

An integer is said to be prime, if it is divisible by exactly two different integers. First few primes are 2, 3, 5, 7, 11, 13, …

解題報告

先得對107 內的素數打表只有664580個,如此數據量級就減小了100倍

判斷素數a+b=n,只要取素數a,在判斷 n-a 是否為素數即可復雜度o(φ(n))

#include<stdio.h>#include<algorithm>#define MAX_N 10000020#define P_N 664580using namespace std;bool vis[MAX_N];int p[P_N];void init(){ int cnt=0; for(int i=2;i*i<=MAX_N;i++) if(!vis[i]) for(int k=i*i;k<MAX_N;k+=i) vis[k]=true; for(int i=2;i<MAX_N;i++) if(!vis[i]) p[cnt++]=i;}int main(){ init();int T; scanf("%d",&T); for(int t=1;t<=T;t++){ int n; scanf("%d",&n); int ans=0; for(int i=0;p[i]<=n/2;i++){ if(!vis[n-p[i]]) ans++; } printf("Case %d: %d/n",t,ans); } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 微山县| 中西区| 保德县| 连城县| 镇安县| 灵台县| 新龙县| 射阳县| 嘉鱼县| 白河县| 门头沟区| 昆明市| 九江县| 云梦县| 商城县| 盐边县| 东莞市| 荣成市| 达州市| 霍邱县| 南和县| 平昌县| 蓝山县| 弋阳县| 麦盖提县| 永城市| 托克逊县| 台北县| 龙泉市| 兴宁市| 陆良县| 临清市| 漠河县| 阿拉善右旗| 资兴市| 盐山县| 监利县| 江华| 武宁县| 陕西省| 汾阳市|