码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #324 (Div. 2) D - Dima and Lisa(哥德巴赫猜想)

时间:2016-04-30 12:49:03      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:

 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 }

 

Codeforces Round #324 (Div. 2) D - Dima and Lisa(哥德巴赫猜想)

标签:

原文地址:http://www.cnblogs.com/zstu-jack/p/5448443.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!