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.
publicstaticintgetTotalX(List<Integer>a,List<Integer>b){// Write your code hereintgcdNumber=Collections.max(b);intlcmNumber=Collections.max(a);inttotal=0;for(inti=0;i<b.size();i++){gcdNumber=gcd(gcdNumber,b.get(i));}for(inti=0;i<a.size();i++){lcmNumber=lcm(lcmNumber,a.get(i));}System.out.println(gcdNumber);System.out.println(lcmNumber);if(gcdNumber%lcmNumber==0){intcount=1;while(gcdNumber>=(lcmNumber*count)){if((gcdNumber%(lcmNumber*count))==0){total++;}count++;}}System.out.println(total);returntotal;}staticintgcd(inta,intb){if(a==0)returnb;returngcd(b%a,a);}// function to calculate// lcm of two numbers.staticintlcm(inta,intb){return(a*b)/gcd(a,b);}
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 →
Java Euclidean Algorithm