-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1349.cpp
More file actions
45 lines (41 loc) · 862 Bytes
/
1349.cpp
File metadata and controls
45 lines (41 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
bool *isPrime = new bool[5000001];
void isPrime3(int n) {
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i <= n; i++) {
isPrime[i] = true;
}
for (int i = 2; i <= n; i++) {
if (isPrime[i]) {
for (int j = i * 2; j <= n; j += i) {
isPrime[j] = false;
}
}
}
}
int main(void)
{
int T;
cin >> T;
while(T--)
{
int m, n, k = 1, ch = 0;
cin >> m >> n;
if(m > n)
swap(m, n);
isPrime3(n);
for(int i = m; i <n-11; i++)
{
if(isPrime[i] && isPrime[i+6] && isPrime[i+12])
{
cout << k++ << ": " << i <<"-" <<i+6 << "-" << i+12 <<"\n";
ch = 1;
}
}
if(ch == 0)
cout << "No Sexy Prime Triplets!\n";
}
return 0;
}