CF735D Taxes

CF735D Taxes

第一次碰到哥德巴赫猜想的题目.
首先考虑质数,直接输出1
考虑1,直接输出1
考虑偶数.可以分解成两个质数.
考虑不是质数奇数,奇数必须有一奇数一偶数相加.
偶数为质数的只有2,所以判断这个数减去2是否是质数
如果是的话,输出2
否则输出3.

/*header*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i , x, p) for(int i = x;i <= p;++ i)
#define sep(i , x, p) for(int i = x;i >= p;-- i)
#define gc getchar()
#define pc putchar
#define ll long long
#define mk make_pair
#define fi first
#define se second
using std::min;
using std::max;
using std::swap;

inline int gi() {
    int x = 0,f = 1;char c = gc;
    while(c < '0' || c > '9') {if(c == '-')f = -1;c = gc;}
    while(c >= '0' && c <= '9') {x = x * 10 + c - '0';c = gc;}return x * f;
}

void print(int x) {
    if(x < 0) pc('-') , x = -x;
    if(x >= 10) print(x / 10);
    pc(x % 10 + '0');
}

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 = gi();
    if(isprime(n)) puts("1");
    else if( !(n & 1) ) puts("2");
    else if(isprime(n - 2)) puts("2");
    else puts("3");
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/gzygzy/p/10197793.html
今日推荐