您的位置:首页 > 其它

CodeForces - 735D Taxes 数论 哥德巴赫猜想和弱哥德巴赫猜想

2017-08-09 16:55 429 查看
http://codeforces.com/problemset/problem/735/D

D. Taxes

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
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.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) —
the total year income of mr. Funt.

Output

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.

Examples

input
4


output
2


input
27


output
3


题意:将一个数n分成若干份,价值是每份的它的最大因子和(不是本身),求最小价值。如27分成3 11 13,价值就是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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: