mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 18:56:28 +00:00
38 lines
650 B
C++
38 lines
650 B
C++
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
bool isPrime(int x) {
|
|
if (x == 1) {
|
|
return false;
|
|
}
|
|
if (x == 2) {
|
|
return true;
|
|
}
|
|
if (x % 2 == 0) {
|
|
return false;
|
|
}
|
|
for (int i = 2; i * i <= x; i++) {
|
|
if (x % i == 0) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main() {
|
|
int n, k;
|
|
bool flag = false;
|
|
cin >> n >> k;
|
|
for (int i = 2; i + k <= n; i++) {
|
|
if (isPrime(i) && isPrime(i + k)) {
|
|
cout << i << ' ' << i + k << endl;
|
|
flag = true;
|
|
}
|
|
}
|
|
if (!flag) {
|
|
cout << "empty" << endl;
|
|
}
|
|
return 0;
|
|
}
|