AcWing 4268. 性感素数
原题链接
简单
作者:
YAX_AC
,
2024-12-09 19:39:59
,
所有人可见
,
阅读 2
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
LL p(LL x)
{
if(x<2) return 0;
for(LL i = 2; i<=x/i; i++)
{
if(x%i==0) return 0;
}
return 1;
}
int main()
{
LL n;
cin>>n;
LL a = n-6;
LL b = n+6;
if(p(n) && (p(a) || p(b)))
{
puts("Yes");
// print in the next line the other sexy prime
if(p(a)) cout<<a<<endl;
else cout<<b<<endl;
}
else
{
puts("No");
for(LL i = n+1; ; i++)
{
//print in the next line the smallest sexy prime
if(p(i) && (p(i-6) || p(i+6)))
{
cout<<i;
break;
}
}
}
return 0;
}