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.
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, where i=1,2,3... until i*f<=g;