Hello, guys.
Here's the challenge:
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?
I wrote my code:
#include <iostream>
#include <cmath>
using namespace std;
#define MAX_VALUE 2793510720
unsigned int Smallest_Evenly_Divisable = 0;
void Show_Number(unsigned int);
void Show_Number(unsigned int Smallest_Evenly_Divisable)
{
cout << "\n\n" << Smallest_Evenly_Divisable << endl;
}
int main()
{
unsigned i = 0;
for (i = 2520; i < MAX_VALUE; i++)
{
if ( i % 2 == 0 && i % 3 == 0 && i % 4 == 0 && i % 5 == 0 && i % 7 == 0 && i % 8 == 0 && i % 9 == 0 && i % 11 == 0
&& i % 13 == 0 && i % 17 == 0 && i % 19 == 0)
{
Smallest_Evenly_Divisable = i;
Show_Number(Smallest_Evenly_Divisable);
i = MAX_VALUE;
}
}
return 0;
}
and got 116396280 as the answer. However, the official answer is 232792560.
But here's the thing: 116396280 < 232792560 and 116396280 is evenly divisable by {1,2,3...20}.
Am I missing something? It seems to me that my answer is correct. I even created a program to do the 116396280%i, i in {1,2,3...20} operation to be sure; it checks out.
Any help would be appreciated.
Petcheco.