Commit aabc0eca by Andrew Dahl

Solved Probem 5

parent 277e66e0
Showing with 34 additions and 0 deletions
Question:
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Answer: 232792560
#include <iostream>
using namespace std;
int main() {
int low = 1;
int high = 20;
long int highest_possible = 1;
int iter = high * (high - 1);
for(int i = low; i <= high; i++)
highest_possible *= i;
for(long int i = iter; i <= highest_possible; i += iter)
{
for(int j = high-1; j >= low; j--)
if(i % j != 0)
break;
else if(j == low)
{
cout << i << endl;
return 0;
}
}
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