#! 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 g = P * Q == 0 ? 1 : P.gcd(Q) pg = P / g qg = Q / g c = 0 N.times do x, y = gis.map(&:abs) if x == 0 && y == 0 c += 1 next end if P == 0 c += 1 if x % Q == 0 && y % Q == 0 next end if Q == 0 c += 1 if x % P == 0 && y % P == 0 next end x /= g y /= g u, v = [x % 2, y % 2].minmax if u == 0 && v == 1 c += 1 if pg % 2 == 0 || qg % 2 == 0 else c += 1 end end p c