@@ -0,0 +1,1372 @@
+package algorithms.implementation;%0A%0Aimport java.util.Scanner;%0A%0A/**%0A * Challenge: https://www.hackerrank.com/challenges/between-two-sets%0A * %0A * @author Sudharsanan Muralidharan%0A */%0Apublic class BetweenTwoSets %7B%0A%0A  private static int gcd(int a, int b) %7B%0A    if (b == 0) %7B%0A      return a;%0A    %7D%0A    return gcd(b, (a %25 b));%0A  %7D%0A%0A  private static int lcm(int a, int b) %7B%0A    return a * (b / gcd(a, b));%0A  %7D%0A%0A  private static int getNumFactors(int n) %7B%0A    int count = 0;%0A    for (int i = 1; i %3C= Math.sqrt(n); i++) %7B%0A      if (n / i == i) %7B%0A        count++;%0A      %7D else if (n %25 i == 0) %7B%0A        count += 2;%0A      %7D%0A    %7D%0A%0A    return count;%0A  %7D%0A%0A  private static int lcmOf(int%5B%5D arr) %7B%0A    int temp = arr%5B0%5D;%0A    for (int i = 1; i %3C arr.length; i++) %7B%0A      temp = lcm(temp, arr%5Bi%5D);%0A    %7D%0A%0A    return temp;%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    Scanner in = new Scanner(System.in);%0A    int n = in.nextInt();%0A    int m = in.nextInt();%0A    int%5B%5D a = new int%5Bn%5D;%0A    int%5B%5D b = new int%5Bm%5D;%0A%0A    for (int i = 0; i %3C n; i++) %7B%0A      a%5Bi%5D = in.nextInt();%0A    %7D%0A    int lcm = lcmOf(a);%0A%0A    for (int i = 0; i %3C m; i++) %7B%0A      int x = in.nextInt();%0A      if (x %25 lcm == 0) %7B%0A        b%5Bi%5D = x / lcm;%0A      %7D%0A    %7D%0A%0A    int gcd = b%5B0%5D;%0A    for (int i = 1; i %3C m; i++) %7B%0A      gcd = gcd(gcd, b%5Bi%5D);%0A    %7D%0A%0A    System.out.println(getNumFactors(gcd));%0A    in.close();%0A  %7D%0A%7D%0A

Add my solution