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

 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

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

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

D. Dima and Lisa Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given

Codeforces Round #324 (Div. 2)

今天写写cf上以前的水题,找找自信 A. Olesya and Rodion 此题要求一个能被t整除的n位数,直接t为开始,后面全部为0. 当然,需要排除位数为1但t=10的情况. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int n,t,i; scanf("%d%d"

Codeforces Round #214 (Div. 2)---C. Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the

Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has t

Codeforces Round #324 (Div. 2) (快速判断素数模板)

蛋疼的比赛,当天忘了做了,做的模拟,太久没怎么做题了,然后C题这么简单的思路却一直卡到死,期间看了下D然后随便猜了下,暴力了下就过了. A.找一个能被t整除的n位数,那么除了<=10以外,其他都可以用长度为n的10或100,1000 ... 来往上加几个数而得到 #include <iostream> #include <stdio.h> #include <set> #include <algorithm> #include <string.h

Codeforces Round #324 (Div. 2)C. Marina and Vasya set

                                                      C. Marina and Vasya Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. Mor

Codeforces Round #324 (Div. 2) E

这题贪心,考虑先放第一个,然后从第一个数在p中的位置, 不断的往前走,和在他后面的那些数组进行交换,因为这样交换可以提高最大的效率,就是说你花费了1但是使得两个点都朝他的木匾节点减少了1 #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cmath> using namespace std; const int maxn=2

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

Codeforces Round #214 (Div. 2)——Dima and Salad

题目链接 题意: 一行a[i],一行b[i],a和b是一一对应的.选取任意个数对,使得sigma(a)/ sigma(b)等于k,求这时候sigma(a)的最大值 分析: 这个题目关键在于对sigma(a)/ sigma(b)== k的处理.对于这种式子,用每个数的比值显然是不行的,因为没法累加:而且是double型,没法DP 考虑一个每个数对对这个式子的影响,如果每个数都是a = k * b,那么显然是可以的:如果a小于k * b,那么在整体中,当前数对少的数肯定要有一些数对来补偿,也就是说,