思路:
筛法筛出素数,逐个判断即可。#include#include #include using namespace std;const int maxn = 1000010;int cnt, a;int prime[maxn];int isnprime[maxn];void findpri(int lim){ for(int i = 2; i <= lim; ++i){ if(!isnprime[i]) prime[++cnt] = i; for(int j = 1; j <= cnt; ++j){ if(i * prime[j] > lim) break; isnprime[i * prime[j]] = 1; if(i % prime[j] == 0) break; } }}int main(void) { findpri(maxn - 10); while(scanf("%d", &a) && a){ for(int i = 1; i <= cnt; ++i){ if(!isnprime[a - prime[i]]){ printf("%d = %d + %d\n", a, prime[i], a - prime[i]); break; } } } return 0;}