Codeforces 735 D Taxes (哥德巴赫猜想)

题目地址:http://codeforces.com/contest/735/problem/D
题意:Funt想逃税,税收是他的工资的最大能整除的数,问最少要多少的税钱。
思路:哥德巴赫猜想

如果是质数直接输出1(能整除的除了1就是本身,所以为1)
否则如果是偶数输出2(哥德巴赫猜想,偶数可以由两个质数组成)
否则如果该数-2是质数输出2(因为质数里就2一个偶数,所以特判一下)
否则输出3(哥德巴赫猜想,所有数都能由3个质数组成)

哥德巴赫猜想:百度百科链接

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long 
#define N 100010
#define M 50010
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
bool isprime(int n) {
    if(n < 2)return false;
    for(int i = 2; i * i <= n; i++) {
        if(n % i == 0)return false;
    }
    return true;
}
int main() {
    int n;
    while (cin >> n) {
        if (isprime(n)) {
            cout << 1 << endl;
        }
        else if (n % 2 == 0) {
            cout << 2 << endl;
        }
        else if (isprime(n - 2)) {
            cout << 2 << endl;
        }
        else {
            cout << 3 << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值