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.
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int a0 = 0; a0 < t; a0++){
int n = in.nextInt();
System.out.println(check(n));
}
}
public static long check(int n)
{
long a=1;
//finding the lcm of all numbers till n to get answer
for(long b=2;b<=n;b++)
{
a= lcm(b,a);
}
return a;
}
public static long lcm(long a,long b)
{
long z=a<b?a:b;
while(true)
{
if(z%a==0 && z%b==0)
return z;
z++;
}
}
}
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 →
JAVA SOLUTION
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}