Atcoder Beginner 177

Question is https://atcoder.jp/contests/abc177/tasks/abc177_e
solution is https://atcoder.jp/contests/abc177/submissions/16386994
I am getting only one case wrong ,can anybody help??

The weird thing is it says WA on sample, but all the samples are running correctly.

This code is AC https://atcoder.jp/contests/abc177/submissions/16336990
Why ??
Difference is only int in place of long long and gcd function is not written

In C++ 17 gcd(a, b) is a function on its own. Maybe it interferes with your code and there is some error due to it.

Try without your own gcd() function.

https://atcoder.jp/contests/abc177/submissions/16387453 got AC after replacing ll to int and __gcd() function .But why??
__gcd() returns only integer or we are storing in ll also while checking (g==1) ,I didn’t convert 1 int to ll 1 ??
Are these possible cases??

Please read above gcd(a, b) is a function in C++17 with the exact same name, so it might be interfering with with your code.