#!/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 p $<.count{|e| x,y=e.split.map(&:to_i) next if x%g!=0 || y%g!=0 x/=g y/=g g0=(2*a).gcd(2*b) z=b*b-a*a w=z2*x*a+z1*x*b-y -w%g0==0 } end