LightOJ1259 Goldbach`s Conjecture
2018-01-09 11:09
363 查看
题面
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; }
相关文章推荐
- LightOJ 1259 Goldbach`s Conjecture(素数问题,思维)
- Hdu 4715 Difference Between Primes (2013网络赛 warm up) & LightOJ 1259 Goldbach`s Conjecture(素数和差)
- lightOJ 1259 Goldbach`s Conjecture
- lightoj1259 - Goldbach`s Conjecture(水题)
- LightOJ - 1259 Goldbach`s Conjecture (素数筛)
- LightOJ 1259 Goldbach`s Conjecture
- LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)
- LightOJ 1259 - Goldbach`s Conjecture (分解偶数为两个素数之和)
- 【LightOJ1259】Goldbach`s Conjecture(数论)
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
- Goldbach`s Conjecture LightOJ - 1259 (素数筛选法)
- LightOJ1259 Goldbach`s Conjecture
- Lightoj1259——Goldbach`s Conjecture(哥德巴赫猜想)
- LightOJ 1259 Goldbach`s Conjecture
- Goldbach`s Conjecture LightOJ 1259
- 【LightOJ1259】Goldbach`s Conjecture(数论)
- LightOJ 1259 Goldbach`s Conjecture
- LightOJ - 1259 Goldbach`s Conjecture
- LightOj 1259-Goldbach`s Conjecture(素数打表)
- LightOJ 1259 Goldbach`s Conjecture