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.

"Count the number of multiples of LCM that evenly divides the GCD." is the same as "Cound the divisors of (GCD/LCM)"
This will make the loop much easier.

Also notice that if (GCD/LCM) is not in integer, the result is 0.

your modification to the above said approach will give wrong answer. as all mulitples of lcm will not evenly divide the gcd. so you will have to check each multiple individually.

## Between Two Sets

You are viewing a single comment's thread. Return to all comments →

why not

instead of

? Otherwise a very nice solution :)

"Count the number of multiples of LCM that evenly divides the GCD." is the same as "Cound the divisors of (GCD/LCM)" This will make the loop much easier.

Also notice that if (GCD/LCM) is not in integer, the result is 0.

How exactly is one different from the other?

My approach was as follows:

n) prime factors, wherenis the total number of prime factors.your modification to the above said approach will give wrong answer. as all mulitples of lcm will not evenly divide the gcd. so you will have to check each multiple individually.

Another suggestion to reduce the number of loop iterations

then double the count and add 1 if i*i==l

For the problem's testcase (f=4, l=16), won't your loop give count as 1 ?

why is it i*i?

because the value of i will be getting doubled for getting next factor easily.

i can only be multiples of lcm(a), that is why j starts at 2 and increases

thank you so much for your advise askarovdaulet