CodeForces - 735D Taxes (哥德巴赫猜想)

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,那个这个人所交的税就是n的最大因子(不包括n)
现在你将n拆成多个数的和 规则如上 问你所交的税最少是多少
哥德巴赫猜想:任一大于2的偶数都可写成两个质数之和
所以我们分三种情况
1》这个数本身就是质数 答案为1
2》这是数是一个偶数 答案为2
3》这个数是一个奇数n n=奇数+2(n>=5) 假如n-2是一个质数 答案为2
假如n-2不为一个质数 我们就可以把这个数化为 n=(n-3)+3 n-3是一个偶数 答案为3
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<string.h>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<cmath>
13 typedef long long ll;
14 typedef unsigned long long LL;
15 using namespace std;
16 const double PI=acos(-1.0);
17 const double eps=0.0000000001;
18 const int INF=1e9;
19 const int N=100000+100;
20 int prime[N];
21 int check(int x){
22     for(int i=2;i*i<=x;i++){
23         if(x%i==0)return 0;
24     }
25     return 1;
26 }
27 int main(){
28     ll n;
29     while(scanf("%I64d",&n)!=EOF){
30        if(check(n)==1){
31             cout<<1<<endl;
32             continue;
33        }
34        if(n%2==0){
35             cout<<2<<endl;
36             continue;
37        }
38        else{
39             if(check(n-2)==1)cout<<2<<endl;
40             else{
41                 cout<<3<<endl;
42             }
43        }
44     }
45 }

 

 

posted on 2017-08-11 15:29  见字如面  阅读(190)  评论(0编辑  收藏  举报

导航