Codeforces Round #382 (Div. 2) D. Taxes (数论 哥猜 大胆尝试)

时间:2022-07-26
本文章向大家介绍Codeforces Round #382 (Div. 2) D. 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

Copy

4

output

Copy

2

input

Copy

27

output

Copy

3

哥德巴赫猜想 (一)任意大于2的偶数n都可以表示成两个质数的和 (二)任意大于5的整数n都可以表示成三个质数的和 首先n=2或3或者是质数,答案是1,对于大于2的数,如果是偶数,那么答案是2最优(用哥猜结论)

如果是奇数但不是质数,最差答案是3,当且仅当n-2是质数的时候是2~

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rg register ll
#define inf 2147483647
#define lb(x) (x&(-x))
ll sz[200005],n;
template <typename T> inline void read(T& x)
{
    x=0;char ch=getchar();ll f=1;
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}x*=f;
}
inline ll query(ll x){ll res=0;while(x){res+=sz[x];x-=lb(x);}return res;}
inline void add(ll x,ll val){while(x<=n){sz[x]+=val;x+=lb(x);}}//第x个加上val
inline bool f(ll x)
{
	if(x<=3)return 1;
	for(rg i=2;i*i<=x;i++)
	{
		if(x%i==0)return 0;
	}
	return 1;
}
inline ll cnt(ll x)
{
	ll max=-1;
	for(rg i=1;i*i<=x;i++)
	{
		if(x%i==0)max=i;
	}
	return max;
}
int main()
{
	cin>>n;
	ll ans=0;
	if(n<=3||f(n))cout<<1<<endl;
	else
	{
		if(n%2==0)cout<<2<<endl;
		else
		{
			for(rg j=n-2;;j--)
			{
				if(f(j))
				{
					cout<<min(1+cnt(n-j),3ll)<<endl;
					break;
				}
				
			}
		}
	}
    return 0;
    
}