We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
class Solution {
static void Main(String[] args) {
int T = Convert.ToInt32(Console.ReadLine());
for (int a0 = 0; a0 < T; a0++) {
int N = Convert.ToInt32(Console.ReadLine());
long smallestMultiple = SmallestMultiple(N);
Console.WriteLine(smallestMultiple);
}
}
static long SmallestMultiple(int N) {
long smallestMultiple = 1;
for (int i = 2; i <= N; i++) {
smallestMultiple = LCM(smallestMultiple, i);
}
return smallestMultiple;
}
static long GCD(long a, long b) {
while (b != 0) {
long temp = b;
b = a % b;
a = temp;
}
return a;
}
static long LCM(long a, long b) {
return (a * b) / GCD(a, b);
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #5: Smallest multiple
You are viewing a single comment's thread. Return to all comments →
In C#:
using System;
class Solution { static void Main(String[] args) { int T = Convert.ToInt32(Console.ReadLine()); for (int a0 = 0; a0 < T; a0++) { int N = Convert.ToInt32(Console.ReadLine()); long smallestMultiple = SmallestMultiple(N); Console.WriteLine(smallestMultiple); } }
}