Goldbach`s Conjecture LightOJ - 1259 (素数打表 哥德巴赫猜想)

时间:2023-03-08 23:29:38
Goldbach`s Conjecture LightOJ - 1259 (素数打表  哥德巴赫猜想)

题意:

就是哥德巴赫猜想。。。任意一个偶数 都可以分解成两个(就是一对啦)质数的加和

输入一个偶数求有几对。。

解析:

首先! 素数打表。。因为 质数 + 质数 = 偶数 所以 偶数 - 质数 = 质数 。。。 我真是蠢啊

还有  vis要用bool类型的!!!!  int会直接爆

代码如下:

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define maxn 10000000
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;
LL primes[];
bool vis[maxn];
int cnt = ;
void init()
{
mem(vis,);
primes[] = ; primes[] = ;
for(int i=; i<maxn; i++)
if(!vis[i])
{
primes[cnt++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = ;
}
} int main()
{
int T;
init();
int res = ;
cin>> T;
while(T--)
{
int ans = ;
int n;
cin>> n;
for(int i=; i<cnt && primes[i] <= n/; i++)
{
if(!vis[n-primes[i]])
ans++;
}
printf("Case %d: %d\n",++res,ans); } return ;
}