题意:
给出一个n,找有多少对数字(a, b)满足
- both a and b is prime
- a+b = n
- a<=b
题解:
大力筛出1e7内的素数,然后暴力查找满足条件的数对,然后输出
AC代码:
#include <iostream>
#include <stdio.h>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 10;
const ll inf = 0x3f3f3f3f;
typedef long double ld;
#define met(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
inline ll mul(ll x, ll y, ll mod) {ll res = (x * y - (ll)(ld)(x / mod * y + 1e-8) * mod); return res < 0 ? res + mod : res;}
const double PI = acos(-1.0);
const int mod = 1000;
ll qPow(ll base, ll n) {ll res = 1; while(n) {if(n & 1) res = (res * base) % mod; base = (base * base) % mod; n >>= 1;} return res % mod;}
vector<int> prime;
bool vis[maxn];
void getPrime() {
met(vis, false);
rep(i, 2, 10000000 - 1) {
if(vis[i]) continue;
prime.pb(i);
for(int j = i + i; j < 10000000; j += i) {
vis[j] = true;
}
}
}
int main() {
ll n;
getPrime();
int len = prime.size();
int T, cas = 1;
scanf("%d", &T);
while(T--) {
ll ans = 0;
scanf("%lld", &n);
// for(n = 2; n <= 10000000; n+=2) {
rep(i, 0, len - 1) {
if(prime[i] > n - prime[i]) break;
if(!vis[n - prime[i]]) ans++;
}
printf("Case %d: %lld\n",cas++, ans);
// }
}
return 0;
}