国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 易门县| 扶绥县| 嘉兴市| 安陆市| 镇康县| 梁平县| 阜南县| 乡宁县| 石河子市| 阳东县| 凤台县| 什邡市| 乐山市| 万载县| 枣强县| 堆龙德庆县| 扶风县| 仁寿县| 长白| 大冶市| 肃宁县| 高陵县| 永吉县| 宜州市| 三江| 塔城市| 南宫市| 大同县| 全椒县| 开原市| 关岭| 涟源市| 东源县| 安庆市| 屯门区| 确山县| 三穗县| 芷江| 建水县| 玉龙| 宽城|