AcWing 4268. 性感素数
原题链接
简单
C++ 代码
#include <iostream>
using namespace std;
typedef long long LL;
LL n, t;
bool check(const int& k)
{
for (int i = 2; i <= k / i; ++ i)
if (k % i == 0) return false;
return k > 1;
}
int main()
{
cin >> n;
t = n;
if (check(n - 6) && check(n)) cout << "Yes\n" << n - 6;
else if (check(n) && check(n + 6)) cout << "Yes\n" << n + 6;
else
{
while (++ n)
{
if (check(n - 6) && check(n))
break;
}
if (n - 6 < t) cout << "No\n" << n << endl;
else cout << "No\n" << n - 6 << endl;
}
return 0;
}