#!/usr/bin/ruby def egcd(x,y) return [x,1,0] if y==0 g,a,b=egcd(y,x%y) [g,b,a-x/y*b] end a,b=gets.split.map(&:to_i).sort gets if b==0 p $<.count{|e| x,y=e.split.map(&:to_i) x==0&&y==0 } else g,z1,z2=egcd(a,b) a/=g b/=g g0,g1,g2=egcd(2*a,2*b) p $<.count{|e| x,y=e.split.map(&:to_i) next if x%g!=0 || y%g!=0 x/=g y/=g z=b*b-a*a w=z2*x*a+z1*x*b-y if -w%z.gcd(g0)==0 =begin _,k1,k2=egcd(z,g0) e=0 f=0 n=w*k1%g0+g0*e m=(z*n+w)/g0 _d=g1*m+2*b*f _b=g2*m-2*a*f _a=z1*x+b*n-_b _c=z2*x-a*n-_d raise if (_a+_b)*a+(_c+_d)*b!=x raise if (_c-_d)*a+(_a-_b)*b!=y p [_a,_b,_c,_d] =end true else false end } end