题目链接:
LightOJ 1259 Goldbach`s Conjecture
题意:
验证哥德巴赫猜想:大于2的所有偶数都可以表示为两个素数的之和。
n <= 1e7
分析:
素数打表,暴力解。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <climits>
#include <cmath>
#include <ctime>
#include <cassert>
#include <bitset>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
typedef long long ll;
const int MAX_N = 10000010;int T, n, prime_cnt, cases = 0;
int prime[7 * MAX_N / 100];
bitset<MAX_N> bs;void GetPrime()
{prime_cnt = 0;bs.set();for(int i = 2; i < MAX_N; i++){if(bs[i] == 1) prime[prime_cnt++] = i;for(int j = 0; j < prime_cnt && i * prime[j] < MAX_N; j++){bs[i * prime[j]] = 0;if(i % prime[j] == 0) break;}}//printf("prime_cnt = %d\n", prime_cnt);
}int main()
{GetPrime();scanf("%d", &T);while(T--){scanf("%d", &n);int num = 0;for(int i = 0; prime[i] <= n / 2; i++){if(bs[n - prime[i]]) num++;}printf("Case %d: %d\n", ++cases, num);}return 0;
}