Codeforces Round #382 (Div. 1) B. Taxes

来源:互联网 发布:凤凰金融 以大数据 编辑:程序博客网 时间:2024/05/17 07:59


B. 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 partsn1 + 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

题意:funt的年收入是n元,交税的费用=n的最大因数(n自身除外),现在他想逃税,把n拆成任意份,但是每一份不能是1,问他最少要交多少钱的税收。

思路:其实这个我楞是没想出来,上网翻了一下题解,原来一个大于2偶数必定能拆成两个素数相加,那么这道题就很简单了,只有几种情况,如果n是2那么答案就是1,如果n是偶数但大于2,那么答案就是2,如果n是奇数且n是素数答案就是1,如果n是奇数但n不是素数n-2是素数的话,答案就是2,如果n是奇数但n不是素数也不是素数的话,答案就是3。下面给代码:

#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<cmath>#include<queue>#include<string>#include<functional>typedef long long LL;using namespace std;#define maxn 105#define ll l,mid,now<<1#define rr mid+1,r,now<<1|1#define lson l1,mid,l2,r2,now<<1#define rson mid+1,r1,l2,r2,now<<1|1#define pi acos(-1.0)#define inf 0x3f3f3f3fconst int mod = 1e9 + 7;int main(){LL n;while (~scanf("%lld", &n)){if (n == 2){printf("1\n");}else if (n % 2){bool jud1 = false, jud2 = false;for (int i = 2; i <= sqrt(n); i++){if (!(n%i)){jud1 = true;break;}}n -= 2;for (int i = 2; i <= sqrt(n); i++){if (!(n%i)){jud2 = true;break;}}if (!jud1)printf("1\n");else if (jud1&&jud2)printf("3\n");elseprintf("2\n");}elseprintf("2\n");}}



0 0