Commit eca7db7c by Andrew Dahl

Problem #1 Solved

parents
Showing with 29 additions and 0 deletions
Question:
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.
Answer: 233168
#include <iostream>
#include <map>
using namespace std;
int main() {
map<int,int> numbers;
int sum = 0;
for(int i=3; i < 1000; i+=3)
numbers[i] = i;
for(int i=5; i < 1000; i+=5)
numbers[i] = i;
for(map<int,int>::iterator it=numbers.begin(); it != numbers.end(); it++)
sum += (*it).first;
cout << sum;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment