#!/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.gcd a gets;p $<.count{|e|x,y=e.split.map{|e|e.to_i}.sort;x%(b-a)==0&&y%(b-a)==0} end