code forces 382 D 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,让你分成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+5;
const int M = 4e5+5;
int dp[N][21];
int n,sum[N],m=0,p,k;
int Tree[N];
bool isprime(ll n){
    if(n<=1)return false;
    if(n==2)return true;
    else if(n%2==0)return false;
    for(int i=3;(ll)i*i<=n;i+=2)if(n%i==0)return false;
    return true;
}
int main()
{
    ll q;
    scanf("%lld",&q);
    if(isprime(q))puts("1");
    else {
        if(q%2==0)puts("2");
        else {
            if(isprime(q-2))puts("2");
            else puts("3");
        }
    }
    return 0;
}

 

 
posted @ 2016-12-07 20:07  贱人方  阅读(354)  评论(0编辑  收藏  举报