-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path47.cpp
More file actions
75 lines (67 loc) · 1.16 KB
/
Copy path47.cpp
File metadata and controls
75 lines (67 loc) · 1.16 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define MAX 200000
int* seive(int n)
{
int *seivearr, i, j;
seivearr = (int *)malloc(n * sizeof(int));
memset(seivearr, 0, sizeof(int) * n);
for (i = 2; i * i <= n; i++)
{
if (seivearr[i])
continue;
for (j = 2 * i; j < n; j += i)
seivearr[j] = 1;
seivearr[i] = 0;
}
return seivearr;
}
int distinct_primes(int n, int *seivearr)
{
int count = 0, cn = n;
if (!seivearr[n]) return 0;
for (int st = 2; n > 1; st++)
{
if (seivearr[st]) continue;
count += (0 == n % st);
while (n % st == 0)
n /= st;
if (count > 4)
return 0;
}
return count;
}
int main()
{
int *seivearr;
seivearr = seive(MAX);
for (int i = 208; ; i += 4)
{
int dist = distinct_primes(i, seivearr);
if (dist == 4)
{
int prev = -1;
int count = 1;
for (int j = i - 4; j <= i + 4; j++)
{
dist = distinct_primes(j, seivearr);
if (dist == 4 && dist == prev)
count++;
else
count = 1;
prev = dist;
if (count == 4)
{
cout << j - 3 << ", " << j << endl;
return 0;
}
}
}
}
free(seivearr);
return 0;
}