0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-28 12:51:59 +00:00

P2640 神秘磁石

R41164557
This commit is contained in:
Baoshuo Ren 2020-11-03 19:12:08 +08:00 committed by Baoshuo Ren
parent 38e483c67c
commit e441db636c
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

37
problem/P2640/P2640.cpp Normal file
View File

@ -0,0 +1,37 @@
#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;
}