#!/usr/bin/ruby a,b=gets.split.map(&:to_i).sort if b==0 p 0 elsif a==0 gets;p $<.count{|e|x,y=e.split.map &:to_i;x%b==0&&y%b==0} else g=b-a gets;p $<.count{|e|x,y=e.split.map &:to_i;(x%a==0&&y%b==0)||(x%b==0&&y%a==0)||(g!=0&&x%g==0&&y%g==0)} end