'commit'
This commit is contained in:
26
TangDou/XiTi/1143.cpp
Normal file
26
TangDou/XiTi/1143.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
//判断是不是质数
|
||||
bool isPrime(int n) { //最快的方法
|
||||
if (n < 2) return false;
|
||||
if (n == 2 || n == 3) return true;
|
||||
if (n % 6 != 1 && n % 6 != 5) return false;
|
||||
for (int i = 5; i <= floor(sqrt(n)); i += 6)
|
||||
if (n % i == 0 || n % (i + 2) == 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 2; i <= n - 2; ++i) {
|
||||
if (isPrime(i) && isPrime(i + 2)) {
|
||||
cout << i << " " << i + 2 << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user