fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static List<Integer> commonMultiples(int[] arr){
  11. int len = arr.length;
  12.  
  13. int lcm = lcm(arr[0], arr[1]);
  14. for(int i = 1; i < len; i++) {
  15. lcm = lcm(arr[i], lcm);
  16. }
  17. System.out.println(lcm);
  18. List<Integer> commonMultiples = new ArrayList<Integer>();
  19. for(int i = 1; i <= 100; i++) {
  20. commonMultiples.add(lcm * i);
  21. }
  22. return commonMultiples;
  23. }
  24.  
  25. private static int lcm(int a, int b) {
  26. return (a * b) / gcd(a, b);
  27. }
  28.  
  29. private static int gcd(int a, int b) {
  30. if (a == 0)
  31. return b;
  32. return gcd(b % a, a);
  33. }
  34.  
  35. public static void main (String[] args) throws java.lang.Exception
  36. {
  37. int[] a = {2,4};
  38.  
  39. List<Integer> arr = commonMultiples(a);
  40. // your code goes here
  41. }
  42. }
Success #stdin #stdout 0.05s 32028KB
stdin
Standard input is empty
stdout
4