-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem5.cpp
More file actions
35 lines (29 loc) · 813 Bytes
/
problem5.cpp
File metadata and controls
35 lines (29 loc) · 813 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
#include <iostream>
#include <vector>
#include <map>
#include <cassert>
#include "mathsutils.h"
#include "stringutils.h"
int Problem5(int Max)
{
std::map<int, int> maxElements;
for(int i = 1 ; i <= Max ; ++i)
{
std::vector<int> factors = PrimeFactors<int>(i);
auto factorCounts = CountElements<int>(factors);
// Update the max elements with the prime factors for this number
for(auto e : factorCounts)
{
if(!maxElements.contains(e.first))
{
maxElements[e.first] = e.second;
}
else
{
maxElements[e.first] = std::max(maxElements[e.first], e.second);
}
}
}
int answer = NumberFromPrimeFactorCounts<int>(maxElements);
return answer;
}