原题传送门
智推的一道恶意评分数学水题~~
分类讨论
- n 为 质 数 n为质数 n为质数: a n s = 1 ans=1 ans=1
- n 为 偶 数 ( ! = 2 ) n为偶数(!=2) n为偶数(!=2): 由 哥 德 巴 赫 猜 想 可 得 a n s = 2 由哥德巴赫猜想可得ans=2 由哥德巴赫猜想可得ans=2
- n 为 奇 数 n为奇数 n为奇数:方法是拆成一个奇质数+一个偶数的形式,又需要讨论偶数是啥:若偶数是2,即 ( n − 2 ) (n-2) (n−2)是质数, a n s = 2 ans=2 ans=2;若偶数 > 2 >2 >2, 化 归 到 第 二 种 情 况 , a n s = 2 + 1 = 3 化归到第二种情况,ans=2+1=3 化归到第二种情况,ans=2+1=3
Code:
#include <bits/stdc++.h>
using namespace std;
bool check(int x){
for (int i = 2; i <= sqrt(x); ++i) if (x % i == 0) return 0;
return 1;
}
int main(){
int x;
scanf("%d", &x);
if (check(x)) puts("1"); else
if (!(x & 1) || (x & 1) && check(x - 2)) puts("2"); else puts("3");
return 0;
}

博客给出一道Codeforces恶意评分数学水题的题解。通过分类讨论求解,当n为质数时答案为1;n为非2偶数时,根据哥德巴赫猜想答案为2;n为奇数时,拆成奇质数加偶数形式,再根据偶数情况确定答案,可能为2或3。
1655

被折叠的 条评论
为什么被折叠?



