-
Notifications
You must be signed in to change notification settings - Fork 0
/
E5.java
59 lines (58 loc) · 1.36 KB
/
E5.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N?*/
import java.util.Scanner;
class E5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int r[]=new int[t];
for(int x=0;x<t;x++)
{
int n=sc.nextInt();
int ar[]=new int[n-1];
for(int y=0;y<n-1;y++)
{
ar[y]=y+2;
}
boolean once=false;
int i=2;
r[x]=1;
while(!isOne(ar))
{
for(int y=0;y<n-1;y++)
{
if(ar[y]%i==0)
{
ar[y]/=i;
once=true;
}
}
if(once)
{
once=false;
r[x]*=i;
}
else
{
i++;
}
}
}
for(int x=0;x<t;x++)
{
System.out.println(r[x]);
}
}
public static boolean isOne(int ar[])
{
for(int x=0;x<ar.length;x++)
{
if(ar[x]!=1)
{
return false;
}
}
return true;
}
}