import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
	long ans;
    
    if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    }
	long ndivc = b/c - a/c;
    if(a%c == 0) ndivc++;
    long ndivd = b/d - a/d;
    if(a%d == 0) ndivd++;
    long lcm = c * d / gcd(c, d);
    long ndivlcm = b/lcm - a/lcm;
    if(a%lcm == 0) ndivlcm++;
    
    ans = b - a + 1 - ndivc - ndivd + ndivlcm;
    
    System.out.println(ans);
    
  }
  
  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
} import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
	long ans;
    
    if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    }
	long ndivc = b/c - a/c;
    if(a%c == 0) ndivc++;
    long ndivd = b/d - a/d;
    if(a%d == 0) ndivd++;
    long lcm = c * d / gcd(c, d);
    long ndivlcm = b/lcm - a/lcm;
    if(a%lcm == 0) ndivlcm++;
    
    ans = b - a + 1 - ndivc - ndivd + ndivlcm;
    
    System.out.println(ans);
    
  }
  
  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
	long ans;
    
    if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    }
	long ndivc = b/c - a/c;
    if(a%c == 0) ndivc++;
    long ndivd = b/d - a/d;
    if(a%d == 0) ndivd++;
    long lcm = c * d / gcd(c, d);
    long ndivlcm = b/lcm - a/lcm;
    if(a%lcm == 0) ndivlcm++;
    
    ans = b - a + 1 - ndivc - ndivd + ndivlcm;
    
    System.out.println(ans);
    
  } main {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
	long ans;
    
    if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    }
	long ndivc = b/c - a/c;
    if(a%c == 0) ndivc++;
    long ndivd = b/d - a/d;
    if(a%d == 0) ndivd++;
    long lcm = c * d / gcd(c, d);
    long ndivlcm = b/lcm - a/lcm;
    if(a%lcm == 0) ndivlcm++;
    
    ans = b - a + 1 - ndivc - ndivd + ndivlcm;
    
    System.out.println(ans);
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long ans; ans if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    } c > d c d {
      long tmp = c;
      c = d;
      d = tmp;
    } long tmp = c; tmp c c = d c d d = tmp d tmp long ndivc = b/c - a/c; ndivc b/c - a/c b/c b c a/c a c if(a%c == 0) ndivc++; a%c == 0 a%c a c 0 ndivc++ ndivc long ndivd = b/d - a/d; ndivd b/d - a/d b/d b d a/d a d if(a%d == 0) ndivd++; a%d == 0 a%d a d 0 ndivd++ ndivd long lcm = c * d / gcd(c, d); lcm c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d long ndivlcm = b/lcm - a/lcm; ndivlcm b/lcm - a/lcm b/lcm b lcm a/lcm a lcm if(a%lcm == 0) ndivlcm++; a%lcm == 0 a%lcm a lcm 0 ndivlcm++ ndivlcm ans = b - a + 1 - ndivc - ndivd + ndivlcm ans b - a + 1 - ndivc - ndivd + ndivlcm b - a + 1 - ndivc - ndivd b - a + 1 - ndivc - ndivd b - a + 1 b - a b a 1 ndivc ndivd ndivlcm System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  } gcd {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  } if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    } b == 0 b 0 {
      return a;
    } return a; a {
      return gcd(b,a%b);
    } return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());
	long ans;
    
    if (c > d) {
      long tmp = c;
      c = d;
      d = tmp;
    }
	long ndivc = b/c - a/c;
    if(a%c == 0) ndivc++;
    long ndivd = b/d - a/d;
    if(a%d == 0) ndivd++;
    long lcm = c * d / gcd(c, d);
    long ndivlcm = b/lcm - a/lcm;
    if(a%lcm == 0) ndivlcm++;
    
    ans = b - a + 1 - ndivc - ndivd + ndivlcm;
    
    System.out.println(ans);
    
  }
  
  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
}
