Codeforces Round #382 (Div. 2) D. Taxes

来源:互联网 发布:网络通信协议种类 编辑:程序博客网 时间:2024/05/18 11:47

 题意可以理解为一个数最少可以拆成几个质数。

哥德巴赫猜想,一个偶数可以至多拆成两个质数(2只能拆成一个),一个奇数可以至多拆成三个质数(本身是质数的只需要一个,可以拆成2加一个质数的是两个)。

#include<bits/stdc++.h>#define ll long longusing namespace std;bool ispa(int x){    for(int i= 2;1LL*i*i <= x*1LL;i ++){        if(x%i == 0) return false;    }    return true;}int main(){    ll n;    cin >>n;    if(n%2== 0&&n != 2){        cout << 2 << endl;    }    else {        if(ispa(n)){ cout << 1 << endl;}        else {                if(!ispa(n-2)) cout << 3 << endl;                else cout << 2 << endl;        }    }    return 0;}

0 0
原创粉丝点击