Problem

Problem Link

is the smallest number that can be divided by each of the numbers from to without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from to ?

Solution

CodeCPP fileDownload

#include <iostream>
 
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
 
int main(void) {
  int ans = 1;
  for (int i = 1; i <= 20; ++i) {
    ans = lcm(ans, i);
  }
  std::cout << ans << std::endl;
  return 0;
}