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.
Your lcm and gcd functions looks fine. But the way you calculated the lcm or gcd for the whole array is not correct. In your current implementation you will get the lcm or gcd only for the last two elements of the array. Try to find how to calculate those for the whole array.
For step-3, if f evenly divides g, then count the number of multiples of f which evenly divides g.
Evenly divides means if g is divided by f then the remainder will be 0.
g%f==0
and multiple of f means f,2*f,3*f,4*f... so on.
In your case you you have to count the number of multiple of f which evenly divides g. like
g%(f*i)==0,wherei=1,2,3...untili*f<=g;
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 →
Your lcm and gcd functions looks fine. But the way you calculated the lcm or gcd for the whole array is not correct. In your current implementation you will get the lcm or gcd only for the last two elements of the array. Try to find how to calculate those for the whole array.
For step-3, if f evenly divides g, then count the number of multiples of f which evenly divides g. Evenly divides means if g is divided by f then the remainder will be 0.
and multiple of f means f,2*f,3*f,4*f... so on. In your case you you have to count the number of multiple of f which evenly divides g. like