-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp47.cpp
More file actions
55 lines (51 loc) · 1.25 KB
/
Copy pathp47.cpp
File metadata and controls
55 lines (51 loc) · 1.25 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
/**
* The first two consecutive numbers to have two distinct prime factors are:
*
* 14 = 2 * 7
* 15 = 3 * 5
*
* The first three consecutive numbers to have three distinct prime factors
* are:
*
* 644 = 2^2 * 7 * 23
* 645 = 3 * 5 * 43
* 646 = 2 * 17 * 19
*
* Find the first four consecutive integers to have four distinct prime
* factors. What is the first of these numbers?
*
* ANSWER: 134043.
*/
#include <iostream>
#include <algorithm>
#include "euler/prime_factor.hpp"
#include "euler.h"
BEGIN_PROBLEM(47, solve_problem_47)
PROBLEM_TITLE("Distinct primes factors")
PROBLEM_ANSWER("134043")
PROBLEM_DIFFICULTY(1)
PROBLEM_FUN_LEVEL(1)
PROBLEM_TIME_COMPLEXITY("?")
PROBLEM_SPACE_COMPLEXITY("?")
END_PROBLEM()
static void solve_problem_47()
{
const int find_consecutive = 4;
int n = 3;
int num_consecutive = 0;
for (; num_consecutive < find_consecutive; ++n)
{
auto distinct_factors = euler::distinct(euler::factorize(n));
auto num_distinct_factors = std::distance(
distinct_factors.begin(), distinct_factors.end());
if (num_distinct_factors == find_consecutive)
{
++num_consecutive;
}
else
{
num_consecutive = 0;
}
}
std::cout << (n - find_consecutive) << std::endl;
}