nek-lang/examples/euler5.nek
2022-02-11 01:19:45 +01:00

24 lines
463 B
Plaintext

// 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?
//
// Correct Answer: 232_792_560
fun gcd(x, y) {
loop y {
tmp <- x;
x = y;
y = tmp % y;
}
return x;
}
result <- 1;
i <- 1;
loop i <= 20; i = i + 1 {
result = result * (i / gcd(i, result));
}
print result;