Here's Problem 5 - Smallest multiple
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?
How can I improve this code? How to make it faster? Is there a better/faster solution?
#include <iostream>
bool calculate(int number, int n) {
if (n == 0) {
return true;
}
return (number % n != 0) ? false : calculate(number,n-1);
}
int main() {
int number = 20;
int result = number;
while (!calculate(result, number)) {
result += number;
}
std::cout << result << '\n';
}