-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path128.cpp
63 lines (53 loc) · 1.41 KB
/
128.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <cstdio>
#include <cstdlib>
using namespace std;
const int n = 100000, N = n + 10;
long long f[N][6];
int ans = 2000 - 1;
bool is_prime(long long x) {
for (long long i = 2; i * i <= x; ++i)
if (x % i == 0)
return false;
return x != 1;
}
void check(int cnt, long long v) {
if (cnt == 3) {
--ans;
printf("find: %lld. left: %d\n", v, ans);
if (ans == 0) {
exit(0);
}
}
}
int main() {
for (int i = 0; i < 6; ++i)
f[0][i] = 1;
long long cur = 2;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 6; ++j) {
f[i][j] = cur;
cur += i;
}
}
for (int i = 1; i < n; ++i) {
for (int j = 0; j < 6; ++j) {
int cnt = 0;
cnt += is_prime(f[i][j] - f[i - 1][j]);
cnt += is_prime(f[i + 1][j] - f[i][j]);
cnt += is_prime(f[i + 1][j] - 1 - f[i][j]);
cnt += is_prime(f[i + 1][j] + 1 - f[i][j]);
if (j == 0)
cnt += is_prime(f[i + 2][0] - 1 - f[i][j]);
// printf("%d: %d %d %d %d %d\n", f[i][j], f[i - 1][j], f[i + 1][j], f[i + 1][j] - 1, f[i + 1][j] + 1, f[i + 2][0] - 1);
check(cnt, f[i][j]);
}
int cnt = 0;
cnt += is_prime(f[i + 1][0] - 1 - f[i][0]);
cnt += is_prime(f[i + 1][0] - f[i][0]);
cnt += is_prime(f[i + 1][0] - 1 - f[i - 1][0]);
cnt += is_prime(f[i + 2][0] - f[i + 1][0]);
cnt += is_prime(f[i + 2][0] - 1 - f[i + 1][0]);
check(cnt, f[i + 1][0] - 1);
}
return 0;
}