#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from fractions import*\n"
"a,b,c,d=map(int,input().split())\n"
"a-=1\n"
"e=c*d//gcd(c,d)\n"
"print(b-a-b//c+a//c-b//d+a//d+b//e-a//e)\n"
"\"";
  system(s);
  return 0;
}            