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.
JAVA8 CODE
public static int gcd(int x, int y){
if(y==0)
return x;
return gcd(y, x%y);
}
public static int lcm(int x, int y){
return x*y/gcd(x,y);
}
public static int getTotalX(List<Integer> a, List<Integer> b) {
// Write your code here
int count =0;
int Lcm = a.get(0);
for(int i =0;i<a.size();i++){
Lcm= lcm(Lcm,a.get(i));
}
int Gcd=b.get(0);
for(int i =0;i<b.size();i++){
Gcd=gcd(Gcd,b.get(i));
}
for(int i =Lcm;i<=Gcd;i+=Lcm){
if(Gcd%i==0)
count++;
}
return count;
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Between Two Sets
You are viewing a single comment's thread. Return to all comments →
JAVA8 CODE public static int gcd(int x, int y){ if(y==0) return x; return gcd(y, x%y); } public static int lcm(int x, int y){ return x*y/gcd(x,y); }
}
}