s,p,q,x,y;main(f){for(scanf("%d%d%d",&p,&q,&s),y=p,f=q;x=y;f=x)y=f%x;for(;~scanf("%d%d",&x,&y);s-=f?x%f|y%f||(x+y)/f&(p+q)/f%2<1:x||y);s=!printf("%d",s);}