import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  }

  private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  }

  private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  } main {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long A = scanner.nextLong() - 1; A scanner.nextLong() - 1 scanner.nextLong() scanner.nextLong scanner 1 long B = scanner.nextLong(); B scanner.nextLong() scanner.nextLong scanner long C = scanner.nextInt(); C scanner.nextInt() scanner.nextInt scanner long D = scanner.nextInt(); D scanner.nextInt() scanner.nextInt scanner long lcm = lcm(C, D); lcm lcm(C, D) lcm C D System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm)) System.out.println System.out System System.out B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm) B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) B - (B / C) - (B / D) + (B / lcm) - A B - (B / C) - (B / D) + (B / lcm) B - (B / C) - (B / D) B - (B / C) - (B / D) B (B / C) B C (B / D) B D (B / lcm) B lcm A (A / C) A C (A / D) A D (A / lcm) A lcm String[] args args private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  } lcm {
    return i / gcd(i, j) * j;
  } return i / gcd(i, j) * j; i / gcd(i, j) * j i / gcd(i, j) i gcd(i, j) gcd i j j long i i long j j private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  } gcd {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  } if (i > j) return gcd(j, i); i > j i j return gcd(j, i); gcd(j, i) gcd j i while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    } i > 0 i 0 {
      long r = j % i;
      j = i;
      i = r;
    } long r = j % i; r j % i j i j = i j i i = r i r return j; j long i i long j j public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  }

  private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  }

  private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long A = scanner.nextLong() - 1;
    long B = scanner.nextLong();
    long C = scanner.nextInt();
    long D = scanner.nextInt();

    long lcm = lcm(C, D);
    System.out.println(B - (B / C) - (B / D) + (B / lcm) - A + (A / C) + (A / D) - (A / lcm));
  }

  private static long lcm(long i, long j) {
    return i / gcd(i, j) * j;
  }

  private static long gcd(long i, long j) {
    if (i > j) return gcd(j, i);
    while (i > 0) {
      long r = j % i;
      j = i;
      i = r;
    }
    return j;
  }
}
