x,y=map(int,input().split()) cnt=0 P,Q=map(int,input().split()) for i in range(max(P,Q)): def gcd(a,b): a,b=b,a%b if b==0: return (a) def lcm(a,b): return (a*b//gcd(a,b)) if gcd(P,Q)==x and lcm(P,Q)==y: cnt+=1 print(cnt)