import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

} import java.util.*; util.* java public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

} Main public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  } main {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc sc.close() sc.close sc long ansA = func(A-1,C,D); ansA func(A-1,C,D) func A-1 A 1 C D long ansB = func(B,C,D); ansB func(B,C,D) func B C D System.out.println((long)(ansB - ansA)) System.out.println System.out System System.out (long)(ansB - ansA) ansB ansA String[] args args public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  } func {

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  } long gcd = gcd(c,d); gcd gcd(c,d) gcd c d long lcm = c / gcd * d; lcm c / gcd * d c / gcd c gcd d long ans = x - x/c - x/d + x/lcm; ans x - x/c - x/d + x/lcm x - x/c - x/d x - x/c - x/d x x/c x c x/d x d x/lcm x lcm return ans; ans long x x long c c long d d public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  } gcd {

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  } if (x < y) {
      long t = x;
      x = y;
      y = t;
    } x < y x y {
      long t = x;
      x = y;
      y = t;
    } long t = x; t x x = y x y y = t y t while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    } y > 0 y 0 {
      long r = x % y;
      x = y;
      y = r;
    } long r = x % y; r x % y x y x = y x y y = r y r return x; x long x x long y y public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

} public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

} Main
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    long D = sc.nextLong();

    sc.close();

    long ansA = func(A-1,C,D);

    long ansB = func(B,C,D);

    System.out.println((long)(ansB - ansA));
    
  }

  public static long func(long x, long c, long d){

    long gcd = gcd(c,d);
    
    long lcm = c / gcd * d;
    
    long ans = x - x/c - x/d + x/lcm;

    return ans;
  
  }

  public static long gcd(long x, long y){

    if (x < y) {
      long t = x;
      x = y;
      y = t;
    }

    while (y > 0) {
      long r = x % y;
      x = y;
      y = r;
    }

    return x;
    
  }

}