code forces 382 D Taxes(数论--哥德巴赫猜想)
Taxes
2 seconds
256 megabytes
standard input
standard output
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.
As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.
The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
4
2
27
3 【分析】给你一个数n,让你分成k个大于1的数,没个数取他们的最大因子,可以是1但不可以是本身,求最小的因子和。显然如果分成k个
质数的和,那么答案就是k.根据哥德巴赫猜想,任何一个偶数都可以写成两个质数的和,所以对于偶数(除了2),答案就是2,对于质数,
答案就是1,对于非质数的奇数,若可写成2+质数,答案就是2,否则3.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define inf 2e9
#define met(a,b) memset(a,b,sizeof a)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long ll;
using namespace std;
const int N = 1e5+;
const int M = 4e5+;
int dp[N][];
int n,sum[N],m=,p,k;
int Tree[N];
bool isprime(ll n){
if(n<=)return false;
if(n==)return true;
else if(n%==)return false;
for(int i=;(ll)i*i<=n;i+=)if(n%i==)return false;
return true;
}
int main()
{
ll q;
scanf("%lld",&q);
if(isprime(q))puts("");
else {
if(q%==)puts("");
else {
if(isprime(q-))puts("");
else puts("");
}
}
return ;
}
code forces 382 D Taxes(数论--哥德巴赫猜想)的更多相关文章
- CodeForces - 735D Taxes (哥德巴赫猜想)
Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output ...
- Codeforces 735D:Taxes(哥德巴赫猜想)
http://codeforces.com/problemset/problem/735/D 题意:给出一个n,这个n可以分解成 n = n1 + n2 + -- + nk,其中k可以取任意数.要使得 ...
- Codeforces Round #382 (Div. 2) D. Taxes 哥德巴赫猜想
D. Taxes 题目链接 http://codeforces.com/contest/735/problem/D 题面 Mr. Funt now lives in a country with a ...
- CF735D Taxes 哥德巴赫猜想\判定素数 \进一步猜想
http://codeforces.com/problemset/problem/735/D 题意是..一个数n的贡献是它的最大的因子,这个因子不能等于它本身 然后呢..现在我们可以将n拆成任意个数的 ...
- ural 1356. Something Easier(数论,哥德巴赫猜想)
1356. Something Easier Time limit: 1.0 secondMemory limit: 64 MB “How do physicists define prime num ...
- Codefroces 735D Taxes(哥德巴赫猜想)
题目链接:http://codeforces.com/problemset/problem/735/D 题目大意:给一个n,n可以被分解成n1+n2+n3+....nk(1=<k<=n). ...
- D. Taxes 哥德巴赫猜想
http://codeforces.com/contest/735/problem/D 这题其实我还不是很懂,那个只是猜想,然而却用了. 只想说说找到第一小于n的素数这种思路是不行的. 121 = 1 ...
- Codeforces735D Taxes(哥德巴赫猜想)
题意:已知n元需缴税为n的最大因子x元.现通过将n元分成k份的方式来减少缴税.问通过这种处理方式需缴纳的税费. 分析: 1.若n为素数,不需分解,可得1 2.若n为偶数,由哥德巴赫猜想:一个大于2的偶 ...
- *CF2.D(哥德巴赫猜想)
D. Taxes time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
随机推荐
- Unity3D之GUITexture的坐标体系
Unity3D的GUITexture的坐标,其中x和y的取值在0~1之间,层次使用z来划分,值越大越靠前.
- hbase数据迁移-HDFS拷贝
1.把数据表test从hbase下拷出 hdfs dfs -get /hbase/data/default/test /home/hadoop/hbase/test 2.文件放到新集群的系统上 scp ...
- Total Commander 8.52 Beta 1
Total Commander 8.52 Beta 1http://www.ghisler.com/852_b1.php 10.08.15 Release Total Commander 8.52 b ...
- Delphi用QJSON解析JSON格式的数据
本来用superobject来解析JSON已经够用了,可惜这个东东不能在移动端使用,于是找到QJSON来处理. 这是一个国内高手写开源免费的东西,赞一个. 假入数据如下: {"message ...
- OpenCV在VS2005下的配置
http://bbs.ednchina.com/BLOG_ARTICLE_3019518.HTM 这是自己今天刚弄好了之后的一点经历.不是很详细.以后有时间一定要整理整理.
- 《Eclipse中的一些快捷键》
1,window--首选项--Java--templates 自定义模板. 2,快捷键. 2.1 alt+/ 内容辅助. 2.2 ctrl+1 : 对小红×的提供解决法案.大红×(代码错误)必须修改代 ...
- iOS学习之单例模式
单例模式(Singleton) 概念:整个应用或系统只能有该类的一个实例 在iOS开发我们经常碰到只需要某类一个实例的情况,最常见的莫过于对硬件参数的访问类,比如UIAccelerometer.这个类 ...
- time元素和datetime、pubtime属性
time:对一个时间进行标识 <time datetime="2012-12-24">2012-12-24</time> datetime:时间的值 pub ...
- 用javascript简单封装AJAX
1.创建一个AJAX引擎对象 var CreateAjax = function () { var xhr = null; if (window.XMLHttpRequest) { //非IE游览器 ...
- Kali安装小问题解决及一些设置
昨天按照完Kali linux之后,更改了镜像源, 然后运行了 apt-get update && apt-get dist-upgrade 发现要 等大约两个小时才能跟新完毕.. 于 ...