1. 程式人生 > >735D Taxes 數論 哥德巴赫猜想和弱哥德巴赫猜想

735D Taxes 數論 哥德巴赫猜想和弱哥德巴赫猜想

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;
}