原题链接:http://codeforces.com/contest/584/problem/D

题意:

给你一个奇数,让你寻找三个以内素数,使得和为这个奇数。

题解:

这题嘛。。。瞎比搞搞就好,首先寻找一个最大的小于这个数的素数,然后减掉之后,就是一个很小的偶数了,然后由哥德巴赫猜想,这个偶数一定能够分解成两个素数的和,然后再瞎比暴力一下就好。复杂度大概是$O(\sqrt{n}log(n))$。

代码:

#include<iostream>
#include<cstring>
using namespace std; int n; bool check(int x) {
for (int i = ; i * i <= x; i++)
if (x % i == )return false;
return true;
} int main() {
cin >> n;
if (check(n)) {
cout << << endl;
cout << n << endl;
return ;
}
for (int i = n; i >= ; i -= ) {
if (check(i)) {
int j = n - i;
if (check(j)) {
cout << << endl;
cout << i << " " << j << endl;
return ;
}
for (int k = j - ; k >= ; k--) {
if (check(k) && check(j - k)) {
cout << << endl;
cout << i << " " << k << " " << j - k << endl;
return ;
}
}
}
}
return ;
}

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

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

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

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  3. Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)

                                                     D. Dima and Lisa Dima loves representing an odd num ...

  4. Codeforces Round #324 (Div. 2) D

    D. Dima and Lisa time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  5. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  6. Codeforces Round #324 (Div. 2) (哥德巴赫猜想)

    题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...

  7. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  8. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  9. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

随机推荐

  1. leetcode 【 Convert Sorted List to Binary Search Tree 】python 实现

    题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...

  2. Vue声明渲染以及axios实例

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  3. Mac: mac git 的安装 及实现自动补全

    1.检查是否装了brew $ brew list 如果没有,拷贝以下命令到终端 回车.可以安装好brewruby -e "$(curl -fsSL https://raw.githubuse ...

  4. Leetcode 553.最优除法

    最优除法 给定一组正整数,相邻的整数之间将会进行浮点除法操作.例如, [2,3,4] -> 2 / 3 / 4 . 但是,你可以在任意位置添加任意数目的括号,来改变算数的优先级.你需要找出怎么添 ...

  5. POJ 3254:Corn Fields(状态压缩DP)

    题目大意:一个矩形的草地,分为多个格子,有的格子可以有奶牛(标为1),有的格子不可以放置奶牛(标为0),计算摆放奶牛的方案数. 分析: f[i,j]表示第i行状态为j的方案总数. 状态转移方程f[i, ...

  6. CLion 使用笔记(三)

    我已经在博客里面发布了好几篇 CLion 使用笔记了,没追究这是第几篇,姑且算作第三篇. 我的 CLion 是搭配了 MSYS2 和 Conan 使用的.MSYS2 提供 C++ toolchain. ...

  7. hihoCoder #1758 加减

    $\DeclareMathOperator{\lowbit}{lowbit}$ 题目大意 对于一个数 $x$,设它最低位的 1 是第 $i$ 位,则 $\lowbit(x)=2i$ . 例如 $\lo ...

  8. [luogu2044][NOI2012] 随机数生成器 [矩阵快速幂]

    题面: 传送门 思路: 看一眼这个公式: $x\left[n+1\right]=\left(a\ast x\left[n\right]+c\right) mod m$ 递推,数据范围$n\leq 10 ...

  9. Activity启动创建 (AcitivtyManageService,ActivityThread,Activity)

    ActivityThead,ActivityManagerService,Activity  <<Android内核剖析>>中有一章节专门介绍 Activity框架和管理结构A ...

  10. springboot 热加载的问题 idea下的springboot热加载的

    最近在学spring框架,使用的是springboot可以省去很多的配置,可谓是初学者的福音啊. 尤其是在刚写代码的时候,都想马上看到自己写出来的效果,看看能不能输出hello world,所以要不断 ...