From 865c68d8ba40d1a276c1dd7333d321ad26c10e58 Mon Sep 17 00:00:00 2001 From: Jorge Guerrero Date: Thu, 10 Oct 2019 10:47:07 +0200 Subject: [PATCH] Added C solution for smallest multiple problem --- Solutions/Smallest_multiple.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Solutions/Smallest_multiple.c diff --git a/Solutions/Smallest_multiple.c b/Solutions/Smallest_multiple.c new file mode 100644 index 0000000..306674c --- /dev/null +++ b/Solutions/Smallest_multiple.c @@ -0,0 +1,28 @@ +#include + +int gcd(int a, int b) { + if (b==0){ + return a; + } + return gcd(b, a%b); +} + + +int main() { + int T, N, lcm; + scanf("%d", &T); + + for (int i = 0; i < T; i++) + { + scanf("%d", &N); + lcm = 1; + for (int j = 2; j <= N; j++) + { + lcm = ((j * lcm) / gcd(j, lcm)); + } + printf("%d \n", lcm); + } + + + return 0; +} \ No newline at end of file