-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem47.cpp
67 lines (61 loc) · 1.23 KB
/
problem47.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
64
65
66
67
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
#define N 1e6
vector<bool> isPrime(N+1,true);
vector<int> primes;
void sieve()
{
isPrime[1] = true;
isPrime[2] = true;
for (int i = 2; i <= sqrt(N);i++){
for (int j = i*i; j<=N;j+=i){
isPrime[j] = false;
}
}
}
void createPrimes()
{
for (size_t i = 1; i<=N; i++){
if (isPrime[i]) primes.push_back(i);
}
}
int getNumDistinctPrimes(int i)
{
int p = 1;
map<int,bool> divides;
int count = 0;
while (i != 1){
if (i % primes[p] == 0){
i /= primes[p];
if(!divides[primes[p]]){
count++;
divides[primes[p]] = true;
}
}else{
p++;
if (p>=primes.size()) {cout<<"error"<<endl;exit(0);}
}
}
return count;
}
int main()
{
sieve();
createPrimes();
int i = 100;
int ans = 0;
while(true){
if (getNumDistinctPrimes(i) == 4 &&
getNumDistinctPrimes(i+1) == 4 &&
getNumDistinctPrimes(i+2) == 4 &&
getNumDistinctPrimes(i+3) == 4){
ans = i;
break;
}
i++;
}
cout<<ans<<endl;
}