「一本通 6.2 练习 3」Goldbach's Conjecture

#include<bits/stdc++.h>
using namespace std; 
const int N = 1e9 + 7;
int pr[N / 5], ct;
bool isP[N];
int ass() {
    isP[1] = true, isP[0] = true;
    for (int i = 2; i < 1e5 + 1; ++i) {
        if (isP[i]) continue;
        pr[++ct] = i;
        for (int j = i + i; j < 1e5 + 1; j += i)
            isP[j] = true;
    }
    return 0;
}
int main() {
    ass();

    while (1 + 1 == 2) {
        int x;
        cin >> x;
        if (x == 0) break;
        if (x == 1 || x == 2 || x % 2 != 0) {
            cout << "Goldbach's conjecture is wrong.\n";
            continue;

        }
        bool s = 0;
        for (int i = 3; i <= x; i++) {
            if (!isP[i] && !isP[x - i]) {
                cout << x << " = " << i << " + " << x - i << endl; s = 1;
                break;
            }

        }
        if (s == 0) {
            cout << "Goldbach's conjecture is wrong.\n";
        }
    }
}

转载请注明来源
sd12