Help in CF Problem Round 489 Prob B

codeforces
round-489

#1

I don’t know why my solution is giving WA. Though it is not the approach given in the editorials still I can’t figure out where my solution is wrong.

Question Link :
http://codeforces.com/contest/992/problem/B

My Solution :
http://codeforces.com/contest/992/submission/39371128


#2

Your assumption that if xy is a perfect square then root of it will be a valid pair seems wrong. In the 15th test case where you are getting wrong answer (r,r) is not a valid pair. So i modified that statement to
if(r
r==xy && __gcd(r,r)==x)
ans–;
The output comes 16 now. Try to resumbit it now


#3

__gcd(r,r) will be r which may or may not be equal to x but outside the loop you are checking r*r==xy then subtracting 1 from ans but (r,r) may not have been taken into account.