wordpress手机顶部菜单郑州seo培训
前置知识
哥德巴赫猜想,任一大于 2 2 2 的偶数都可写成两个素数之和。
思路
我们可以分类讨论一下。
- n n n 一开始就是质数。直接输出即可
- n n n 是偶数,那么一定可以写成两个质数之和。那么暴力枚举两个质数即可。
如果以上均不符合,计 n n n 以内最大的质数为 x x x,它们的差为 y y y。
因为 x x x 一定是奇数,且此时 n n n 也一定是奇数。奇数减去奇数一定是偶数。所以直接暴力么枚举两个质数即可。
代码
#include<bits/stdc++.h>
#include<cstring>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<map>
#define ll long long
#define lhs printf("\n");
using namespace std;
const int N=3e5+10;
const int M=2024;
const int inf=0x3f3f3f3f;
ll n,x,y;
bool check(ll x)
{if(x==1)return 0;for(ll i=2;i<=sqrt(x);i++){if(x%i==0)return 0;}return 1;}
int main()
{ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n;if(check(n)){cout<<"1\n";cout<<n;return 0;}if(n%2==0){cout<<"2\n";for(ll i=n-1;i>=2;i--){if(check(i)){ll k=n-i;if(check(k)){cout<<i<<" "<<k<<"\n";return 0;}}}}for(ll i=n-1;i>=2;i--){if(check(i)){x=i;break;}}ll y=n-x;if(check(y)){cout<<"2\n";cout<<x<<" "<<y;return 0;}if(y%2==0){cout<<"3\n";for(ll i=y-1;i>=2;i--){if(check(i)){ll k=y-i;if(check(k)){cout<<i<<" "<<k<<" "<<x;return 0;}}}}return 0;
}