import java.util.*;
import java.util.stream.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner in = new Scanner(System.in);
    long A = in.nextLong(), B = in.nextLong(), C = in.nextLong(), D = in.nextLong();
    System.out.println((B - A + 1) - calc(A, B, C) - calc(A, B, D) + calc(A, B, lcm(C, D)));
  }

  public static long calc(long a, long b, long c) {
    return b / c - (a - 1) / c;
  }

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

  public static long lcm(long x, long y) {
    return x * (y / gcd(x, y));
  }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz