codeforces #382 div2 D. Taxes(哥德巴赫猜想)

题目链接

题意:一个人有n元前,他要交的税是n的最大因子(除n外),现在这个投机倒把者想把前分成k部分(k为大于等于1的任意值)每部分不能为1,分别交税,问最少交多少税。

思路:要说因子小。。很容易想到素数。。。然后就很容易想到了维基百科_哥德巴赫猜想

内容是:任何一个大于2的偶数可以写成两个素数的和。

(虽然是一个猜想没有被证明。。。但是1E9这种级别正确性还是很显然的2333

那么任何大于2的偶数,答案就是2

奇数可以分成一个3和一个偶数,答案为3.

不过这可能还不够优,这也是这道题的两个trick所在:

如果该数本身为素数,那么不用分(k取1),答案为1

如果该数减去2为素数,那么答案为2.

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年11月29日 星期二 11时36分56秒
 4File Name :code/cf/#382/D.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33LL n;
34bool prime( LL x)
35{
36    for ( LL i = 2 ; i*i <= x ; i++)
37    {
38	if (x%i==0) return false;
39    }
40    return true;
41}
42LL solve( LL x)
43{
44    if (prime(x)) return 1;
45    if (x%2==0) return 2;
46    if (x%2==1)
47    {
48	if (prime(x-2)) return 2;
49	else return 3;
50    }
51}
52int main()
53{
54	#ifndef  ONLINE_JUDGE 
55	freopen("code/in.txt","r",stdin);
56  #endif
57	cin>>n;
58	LL ans = solve(n);
59	cout<<ans<<endl;
60
61  #ifndef ONLINE_JUDGE  
62  fclose(stdin);
63  #endif
64    return 0;
65}