WA in GCD and LCM

Why is the code not getting accepted? Even if I type casted them in long. I even tried long long and still it wasn’t working! please help! I’m just a beginner!
Here’s the question
Here’s my solution

I am not well-versed with C, so I can’t find the mistake in your code. But I can certainly give you the test case on which it fails.

Input

1
1000000 999999

Expected Output

1 999999000000

Your Output

1 -728379968

1 Like

just define num1 and num2 long.
this is happening because of integer overflow.

and the algorithm you are using to calculate is very slow so you will get TLE even if you declare them long

1 Like

either learn Euclid algorithm to calculate GCD here : Program to Find GCD or HCF of Two Numbers - GeeksforGeeks

or here is my number theory course series , you can learn GCD and more concepts of number theory : null - YouTube

1 Like

Thank you so much!
your videos look quite informative!

Thanks…I needed that!

1 Like

you’re welcome

You are welcome!