You are viewing a single comment's thread. Return to all comments →
for (int i=f;i<=l;i+=f)
for(int i = f, j =2; i<=l; i=f*j,j++)
? 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:
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
for (int i=f;i*i<l;i+=f)
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