mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 13:18:46 +00:00
4268. 性感素数
https://www.acwing.com/problem/content/submission/code_detail/14678536/
This commit is contained in:
parent
a30aba29cc
commit
49673d472b
42
AcWing/4268/4268.cpp
Normal file
42
AcWing/4268/4268.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
bool isPrime(int x) {
|
||||
if (x <= 1) return false;
|
||||
|
||||
for (int i = 2; i * i <= x; i++) {
|
||||
if (x % i == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int x;
|
||||
|
||||
cin >> x;
|
||||
|
||||
if (isPrime(x) && isPrime(x - 6)) {
|
||||
cout << "Yes" << endl
|
||||
<< x - 6 << endl;
|
||||
} else if (isPrime(x) && isPrime(x + 6)) {
|
||||
cout << "Yes" << endl
|
||||
<< x + 6 << endl;
|
||||
} else {
|
||||
cout << "No" << endl;
|
||||
|
||||
while (!(isPrime(x) && (isPrime(x - 6) || isPrime(x + 6)))) x++;
|
||||
|
||||
cout << x << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
AcWing/4268/data/11.ans
(Stored with Git LFS)
Normal file
BIN
AcWing/4268/data/11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AcWing/4268/data/11.in
(Stored with Git LFS)
Normal file
BIN
AcWing/4268/data/11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AcWing/4268/data/12.ans
(Stored with Git LFS)
Normal file
BIN
AcWing/4268/data/12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
AcWing/4268/data/12.in
(Stored with Git LFS)
Normal file
BIN
AcWing/4268/data/12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user