AcWing 4268. 性感素数
记录一下自己的脑残时刻,不是很难的题,可能太久没好好打比赛解题了,困了半天,用筛法筛了半天都不对,好吧我太菜了,看一下解析还卡了半天边界问题,我可真是太菜了,啊啊啊啊…
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e12;
bool su(int x){
if(x == 1 || x < 0) return false;
for(int i = 2; i <= sqrt(x); i ++ ){
if(x % i == 0) return false;
}
return true;
}
signed main()
{
int n;
cin>>n;
if(su(n)){
if(n >= 6 && su(n - 6)){
cout<<"Yes"<<endl;
cout<<n - 6<<endl;
}
else if(su(n + 6)){
cout<<"Yes"<<endl;
cout<<n + 6<<endl;
}
else{
cout<<"No"<<endl;
for(int i = n; i < N; i ++ ){
if(su(i) && (su(i - 6) || su(i + 6))){
cout<<i<<endl;
break;
}
}
}
}
else{
cout<<"No"<<endl;
for(int i = n; i < N; i ++ ){
if(su(i) && (su(i - 6) || su(i + 6))){
cout<<i<<endl;
break;
}
}
}
return 0;
}