integer(8)a,b,c,d,L;read*,a,b,c,d;a=a-1;L=c*d/GCD(c,d);print*,((b-b/c-b/d+b/L)-(a-a/c-a/d+a/L));
contains;recursive function GCD(a,b)result(res);integer(8)a,b;if(b>0)then;res=GCD(b,mod(a,b));else;res=a;endif;endfunction;end