-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem5.h
More file actions
49 lines (41 loc) · 964 Bytes
/
problem5.h
File metadata and controls
49 lines (41 loc) · 964 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Created by Karun Ram, Pratim Chowdhary on 4/27/22.
//
#ifndef PROJECT_EULER_PROBLEM5_H
#define PROJECT_EULER_PROBLEM5_H
#include "iostream"
using namespace std;
long factorial(int n) {
if (n == 0) {
return 1;
}
return n * factorial(n - 1);
}
long find_smallest_multiple(int n) {
long fact = factorial(n);
int count = n;
while (count > 2) {
if (fact % count == 0) {
bool div = true;
long temp = fact / count;
for (int i = n; i > 1; i--) {
if (temp % i != 0) {
div = false;
break;
}
}
if (div) {
fact = temp;
} else {
count--;
}
}
}
return fact;
}
void problem_5_solution(bool log) {
int n = 20;
long r = find_smallest_multiple(n);
if (log) cout << r << endl;
}
#endif //PROJECT_EULER_PROBLEM5_H