CodeForces
来源:互联网 发布:神舟软件科技有限公司 编辑:程序博客网 时间:2024/06/03 14:55
http://codeforces.com/problemset/problem/735/D
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
题解:最优的方法就是把这个数尽可能的分成素数。如果对于素数那么价值就是1,那么对于合数呢。根据哥德巴赫猜想有:任何大于2的偶数都可以分成两个质数和。所以偶数除2之外的价值就是2。根据弱哥德巴赫猜想有:任何大于7的奇数都可以分成三个质数和。但是对于奇数这么分不一定是最优的,如13,可以分成2 11和3 3 5。其实可以发现因为质数中只有2这个偶数,所以如果n-2是素数的话,那么价值就是2了。反之就是3。
代码:
#include<bits/stdc++.h>#define debug cout<<"aaa"<<endl#define mem(a,b) memset(a,b,sizeof(a))#define LL long long#define lson l,mid,root<<1#define rson mid+1,r,root<<1|1#define MIN_INT (-2147483647-1)#define MAX_INT 2147483647#define MAX_LL 9223372036854775807i64#define MIN_LL (-9223372036854775807i64-1)using namespace std;const int N = 100000 + 5;const int mod = 1000000000 + 7;bool judge(int n){for(int i=2;i*i<=n;i++){if(n%i==0){return 0;}}return 1;}int main(){int n;cin>>n;if(judge(n)){puts("1");}else if(n%2==0){puts("2");}else{if(judge(n-2)){puts("2");}else{puts("3");}}return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- MBR简介
- Java校验IP的正则表达式
- ipython 常用命令
- 如何学习正则表达式(校验网址)
- hods--2000
- CodeForces
- 大暑假集训 第二阶段
- eclipse中中文乱码
- hdu6085 手写bitset
- bootstrap-datetimepicker精确到年、月、天、小时、分钟
- python模块下载网址
- swagger nginx 代理出现 no content问题
- HDU
- matlab写入txt、excel 以及关于图的处理