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

哥德巴赫猜想

(世界近代三大数学难题之一)

哥德巴赫1742年给欧拉的信中哥德巴赫提出了以下猜想:任一大于2的偶数都可写成两个质数之和。但是哥德巴赫自己无法证明它,于是就写信请教赫赫有名的大数学家欧拉帮忙证明,但是一直到死,欧拉也无法证明。因现今数学界已经不使用“1也是素数”这个约定,原初猜想的现代陈述为:任一大于5的整数都可写成三个质数之和。欧拉在回信中也提出另一等价版本,即任一大于2的偶数都可写成两个质数之和。今日常见的猜想陈述为欧拉的版本。把命题"任一充分大的偶数都可以表示成为一个素因子个数不超过a个的数与另一个素因子不超过b个的数之和"记作"a+b"。1966年陈景润证明了"1+2"成立,即"任一充分大的偶数都可以表示成二个素数的和,或是一个素数和一个半素数的和"。
今日常见的猜想陈述为欧拉的版本,即任一大于2的偶数都可写成两个素数之和,亦称为“强哥德巴赫猜想”或“关于偶数的哥德巴赫猜想”。

从关于偶数的哥德巴赫猜想,可推出:任一大于7的奇数都可写成三个质数之和的猜想。后者称为“弱哥德巴赫猜想”或“关于奇数的哥德巴赫猜想”。若关于偶数的哥德巴赫猜想是对的,则关于奇数的哥德巴赫猜想也会是对的。弱哥德巴赫猜想尚未完全解决,但1937年时前苏联数学家维诺格拉多夫已经证明充分大的奇质数都能写成三个质数的和,也称为“哥德巴赫-维诺格拉朵夫定理”或“三素数定理”。

 

D. Taxes
time limit per test
2 seconds
memory limit per test
256 megabytes

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

简单的数论问题,答案只有123三种输出,决定于(n-2)是否为素数。

 1 #include<stdio.h>
 2 #include<math.h>
 3 bool judge(long long k)
 4 {
 5     int r = sqrt (k + 1);
 6     for(int i = 2 ;i <= r ;i++)
 7     {
 8         if (k % i == 0)
 9         return 0;
10     }
11     return 1;
12 }
13 long long n;
14 int main()
15 {
16     scanf("%lld",&n);
17     if(judge(n)||n==2|n==3) printf("1\n");
18     else if(n%2==0||judge(n-2)) printf("2\n");
19     else printf("3\n");
20     return 0;
21 }

 

posted @ 2017-03-05 11:11  饼饼饼饼饼  阅读(417)  评论(0编辑  收藏  举报