-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEuler1.cpp
More file actions
31 lines (28 loc) · 883 Bytes
/
Euler1.cpp
File metadata and controls
31 lines (28 loc) · 883 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
#include <iostream>
#include <vector>
// Project Euler
// Multiples of 3 and 5
// Problem 1
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
// The sum of these multiples is 23.
// Find the sum of all the multiples of 3 or 5 below 1000.
int main(int argc, char **argv)
{
std::vector<int> merged;
std::vector<int>::iterator it;
int total = 0;
for (int a = 0; a < 1000; a = a + 3) {
it = merged.begin();
it = merged.insert(it,a);
}
for (int b = 0; b < 1000; b = b + 5) {
it = merged.begin();
it = merged.insert(it,b);
}
sort( merged.begin(), merged.end() );
merged.erase( unique( merged.begin(), merged.end() ), merged.end() );
for(std::vector<int>::iterator it1 = merged.begin(); it1 != merged.end(); ++it1)
total += *it1;
std::cout << "total value of elements summed: " << total << std::endl;
return 0;
}