Codeforces735D Taxes(哥德巴赫猜想)

题意:已知n元需缴税为n的最大因子x元。现通过将n元分成k份的方式来减少缴税。问通过这种处理方式需缴纳的税费。

分析:

1、若n为素数,不需分解,可得1

2、若n为偶数,由哥德巴赫猜想:一个大于2的偶数可以分解成两个素数的和,可得2

3、若n为奇数,n-2为素数,则为2,否则为3。(因为若为奇数要拆,不能拆成1+偶数,至少拆为2+奇数,若此奇数为素数,则输出为2,否则继续拆成3+偶数,那么结果为3(充分利用哥德巴赫猜想的结论))

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1};
const int dc[] = {-1, 1, 0, 0};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
bool judge_prime(int n){
    for(int i = 2; i <= sqrt(n + 0.5); ++i){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}
int main(){
    int n;
    while(scanf("%d", &n) == 1){
        if(judge_prime(n)){
            printf("1\n");
            continue;
        }
        if(n % 2 == 0){
            printf("2\n");
            continue;
        }
        if(n & 1){
            if(judge_prime(n - 2)){
                printf("2\n");
                continue;
            }
            else{
                printf("3\n");
                continue;
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/tyty-Somnuspoppy/p/6114066.html