TheAlgorithms-C/project_euler/Problem 05/sol.c
2020-04-08 09:41:12 -04:00

37 lines
579 B
C

#include <stdio.h>
unsigned long gcd(unsigned long a, unsigned long b)
{
unsigned long r;
if (a > b)
{
unsigned long t = a;
a = b;
b = t;
}
while ((r = (a % b)))
{
a = b;
b = r;
}
return b;
}
unsigned long lcm(unsigned long a, unsigned long b)
{
unsigned long long p = (unsigned long long)a * b;
return p / gcd(a, b);
}
int main(void)
{
unsigned long ans = 1;
unsigned long i;
for (i = 1; i <= 20; i++)
{
ans = lcm(ans, i);
}
printf("%lu\n", ans);
return 0;
}