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 number that is evenly divisible by all of the numbers from 1 to 20?
While trying to solve this problem, i came up with the code i have given here. The codes compiles and runs, but i get a wrong answer. Someone plz show me where i've gone wrong and help me obtain the correct answer.
#include <iostream>
using namespace std;
class common
{
public:
int ans;
void calc();
};
void common:: calc()
{
ans = 0;
int test = 20, flag = 0, i = 1;
while (flag==0)
{
for (i = 1; i<20; i++)
{
if (test%i)
{
if (i==19)
{
ans = test;
flag = 1;
}
}
else
{
test += 20;
continue;
}
}
}
cout << "Answer : \t" << ans << endl;
}
int main()
{
common inst;
inst.calc();
}