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?
#include <iostream>
#include <limits>
using namespace std;
void pause() { cin.ignore(numeric_limits<streamsize>::max(), '\n'); }
int main()
{
int long long currentTest = 1;
bool keepGoing = true;
int arrayCount[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
int boolCount = 0;
while (keepGoing)
{
for (int j = 0; j <= 20; j++)
{
if (currentTest % arrayCount[j] != 0)
{
currentTest++;
boolCount = 0;
break;
}
boolCount++;
if (boolCount == 20)
{
keepGoing = false;
}
}
}
cout << currentTest-1;
pause();
}