Smallest multiple | Project Euler | Problem #5

URL to the problem page: https://projecteuler.net/problem=5

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>
using namespace std;

int main()
{
    long long j = 20, i, result, counter;
    while (true) {
        counter = 0;
        for (i = 1; i < 21; i++) {
            if (j % i != 0) {
                counter++;
                break;
            }
        }
        if (counter == 0) {
            result = j;
            break;
        }
        j++;
    }
    cout << "Smallest positive number that is evenly divisible by all of the numbers from 1 to 20 is  =  " << result << endl;
    return 0;

Comments

My photo
Ercan Tomac
instagram.com/ercantomac