LightOJ1259 Goldbach`s Conjecture

题面

T组询问,每组询问是一个偶数n

验证哥德巴赫猜想

回答n=a+b

且a,b(a<=b)是质数的方案个数

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).

Sol

垃圾题,枚举质数就好

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int __(1e7 + 10); IL ll Read(){
char c = '%'; ll x = 0, z = 1;
for(; c > '9' || c < '0'; c = getchar()) if(c == '-') z = -1;
for(; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * z;
} int prime[__ / 10], num, n, ans;
bool isprime[__]; IL void Prepare(){
isprime[1] = 1;
for(RG int i = 2; i <= __; ++i){
if(!isprime[i]) prime[++num] = i;
for(RG int j = 1; j <= num && i * prime[j] <= __; ++j){
isprime[i * prime[j]] = 1;
if(!(i % prime[j])) break;
}
}
} int main(RG int argc, RG char *argv[]){
Prepare();
for(RG int T = Read(), Case = 1; Case <= T; ++Case){
n = Read(); ans = 0;
for(RG int i = 1; i <= num && prime[i] + prime[i] <= n; ++i) ans += !isprime[n - prime[i]];
printf("Case %d: %d\n", Case, ans);
}
return 0;
}
上一篇:dedecms网站迁移时记得将安装目录放空 附迁移的正确方法


下一篇:linux操作系统语言更改