-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallestMultiple.java
More file actions
52 lines (38 loc) · 894 Bytes
/
Copy pathSmallestMultiple.java
File metadata and controls
52 lines (38 loc) · 894 Bytes
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
import java.util.*;
public class SmallestMultiple
{
public static ArrayList<Long> temp = new ArrayList<Long>();
private static int numbers[] = new int[21];
private static long findLCM(ArrayList<Integer> listOfNumbers)
{
long product = 1;
for (int number : listOfNumbers)
{
LargestPrimeFactor.findLargestFactorPublic(number, temp);
for (long n : temp)
{
if (Collections.frequency(temp, n) > numbers[(int)n])
numbers[(int)n] = Collections.frequency(temp, n);
}
temp.clear();
}
for(int i = 1; i < 21; i++)
{
if (numbers[i] != 0)
{
product *= Math.pow(i, numbers[i]);
}
}
return product;
}
public static void main(String args[])
{
ArrayList<Integer> listOfNumbers = new ArrayList<Integer>();
for(int i=1; i < 21; i++)
{
listOfNumbers.add(i);
numbers[i] = 0;
}
System.out.println(findLCM(listOfNumbers));
}
}