My code works well in the CodeChef Editor. Why does it show runtime error (NZEC) after submitting the code?
@rudra09 Look at the case when number A is less then B.
In this Case your GCD function is failing.
for e.g. if you take a=3 and b=5
then at first step b%a will be 2 which will be rem and acc. to your algo for next iteration b=3 and a=2…
In next iteration rem will be 1 and hence b will be 2 and a=1.
And in the final iteration b%a==0 as 1 divides 2 and this will give b=1 and a=0.
And according to your implementation as b still not equal to zero, it will iterate further,so it will again iterate to next step which will give “divide by zero error” as (1%0).
So, Modify your GCD function accordingly or just Swap(a,b) for a<b case.
Further your code will still give WA as the return type and argument type of LCM function should be long as LCM may be larger than 10^9.
Here is the link of successful submission with few modifications stated above:
https://www.codechef.com/viewsolution/18970549
Hope it help!!