import java.util.Scanner;

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.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  }

  public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  }

  public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  }
} import java.util.Scanner; Scanner 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.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  }

  public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  }

  public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  } main {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  } 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.nextInt(); c sc.nextInt() sc.nextInt sc long d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long lcmCD = lcm(c, d); lcmCD lcm(c, d) lcm c d long cMultiples = b / c - (a - 1) / c; cMultiples b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long dMultiples = b / d - (a - 1) / d; dMultiples b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long cdMultiples = b / lcmCD - (a - 1) / lcmCD; cdMultiples b / lcmCD - (a - 1) / lcmCD b / lcmCD b lcmCD (a - 1) / lcmCD (a - 1) a 1 lcmCD System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples) System.out.println System.out System System.out b - a + 1 - cMultiples - dMultiples + cdMultiples b - a + 1 - cMultiples - dMultiples b - a + 1 - cMultiples - dMultiples b - a + 1 b - a b a 1 cMultiples dMultiples cdMultiples String[] args args public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  } gcd {
    return (a == 0) ? b : gcd(b % a, a);
  } return (a == 0) ? b : gcd(b % a, a); (a == 0) ? b : gcd(b % a, a) (a == 0) a 0 b gcd(b % a, a) gcd b % a b a a long a a long b b public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  } lcm {
    return a * b / gcd(a, b);
  } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b 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.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  }

  public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  }

  public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  }
} 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.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  }

  public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  }

  public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  }
} Main
import java.util.Scanner;

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.nextInt();
    long d = sc.nextInt();

    long lcmCD = lcm(c, d);

    long cMultiples = b / c - (a - 1) / c;
    long dMultiples = b / d - (a - 1) / d;
    long cdMultiples = b / lcmCD - (a - 1) / lcmCD;

    System.out.println(b - a + 1 - cMultiples - dMultiples + cdMultiples);
  }

  public static long gcd(long a, long b) {
    return (a == 0) ? b : gcd(b % a, a);
  }

  public static long lcm(long a, long b) {
    return a * b / gcd(a, b);
  }
}