p,q,x,y,s;
gcd(x,y){return y?gcd(y,x%y):x;}
main(){
scanf("%d%d%*d",&p,&q);
if(p==0&&q==0){
for(;~scanf("%d%d",&x,&y);s+=(x==0)&&(y==0));
return !printf("%d",s);
}
x=gcd(p+q,p-q);y=gcd(p,q);
p=x;q=y;
for(;~scanf("%d%d",&x,&y);s+=!((x%q)|(y%q)|((x+y)%p)));
s=!printf("%d",s);
}