#!/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 (y-z2*x*a-z1*x*b)%(2*a).gcd(2*b).gcd(b*b-a*a)==0 } end