1 #include<bits/stdc++.h> 2 using namespace std; 3 4 /** 5 据哥德巴赫猜想:任意一个偶数可以拆成两个质数 6 n-- 直到质数 t , n-t 是偶数 , 将n-t 拆分成两个质数 7 8 */ 9 10 bool check(int x) { 11 for (int i = 2; i * i <= x; i++) 12 if (x % i == 0) return false; 13 return true; 14 } 15 16 int main() { 17 int n; 18 cin >> n; 19 if (check(n)) { 20 cout << 1 << endl << n<< endl; 21 return 0; 22 } 23 for (int i = n; i >= 0; i -= 2) { 24 if (check(i)) { 25 int j = n - i; 26 if (check(j)) { 27 cout << 2 << endl; 28 cout << i << " " << j << endl; 29 return 0; 30 } 31 for (int k = j - 2; k >= 0; k--) { 32 if (check(k) && check(j - k)) { 33 cout << 3 << endl; 34 cout << i << " " << k << " " << j - k << endl; 35 return 0; 36 } 37 } 38 } 39 } 40 return 0; 41 }
时间: 2024-12-06 01:34:44