-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem1.h
More file actions
35 lines (28 loc) · 728 Bytes
/
problem1.h
File metadata and controls
35 lines (28 loc) · 728 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
//
// Created by Karun Ram, Pratim Chowdhary on 4/19/22.
//
#ifndef PROJECT_EULER_PROBLEM1_H
#define PROJECT_EULER_PROBLEM1_H
#include <set>
#include "iterator"
using namespace std;
int find_multiples_sum(int n, const set<int>& divisors) {
set<int>::iterator itr;
int sum = 0;
for (int i = 0; i < n; i++) {
for (itr = divisors.begin(); itr != divisors.end(); itr++) {
if (i % *itr == 0) {
sum += i;
break;
}
}
}
return sum;
}
void problem_1_solution(bool log) {
int n = 1000;
set<int> divisors = {3, 5};
int sum = find_multiples_sum(n, divisors);
if (log) cout << sum << endl;
}
#endif //PROJECT_EULER_PROBLEM1_H