#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU def gs(); gets.chomp; end def gi(); gets.to_i; end def gss(); gets.chomp.split; end def gis(); gss.map(&:to_i); end # 解説読後 # http://yukicoder.me/problems/849/editorial P, Q = gis N = gi d = P * Q == 0 ? P + Q : P.gcd(Q) if P == 1 || Q == 1 || d == 1 puts N exit end c = 0 N.times do x, y = gis.map(&:abs) if P == 0 && Q == 0 c += 1 if x == 0 && y == 0 next end c += 1 if x % d == 0 && y % d == 0 end p c