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.nextInt();
      long d = sc.nextInt();
      long lcm = lcm(c, d);
      long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
      long cnt2 = b - b / c - b / d + b / lcm;

      System.out.println(cnt2 - cnt1);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }

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

      System.out.println(cnt2 - cnt1);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }

  private static long lcm(long a, long b) {
    return a / gcd(a, b) * 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 lcm = lcm(c, d);
      long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
      long cnt2 = b - b / c - b / d + b / lcm;

      System.out.println(cnt2 - cnt1);
  } main { 
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextInt();
      long d = sc.nextInt();
      long lcm = lcm(c, d);
      long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
      long cnt2 = b - b / c - b / d + b / lcm;

      System.out.println(cnt2 - cnt1);
  } 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 lcm = lcm(c, d); lcm lcm(c, d) lcm c d long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm; cnt1 (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm (a - 1) - (a - 1) / c - (a - 1) / d (a - 1) - (a - 1) / c - (a - 1) / d (a - 1) a 1 (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / lcm (a - 1) a 1 lcm long cnt2 = b - b / c - b / d + b / lcm; cnt2 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 System.out.println(cnt2 - cnt1) System.out.println System.out System System.out cnt2 - cnt1 cnt2 cnt1 String[] args args private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  } gcd {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  } if(b == 0)
      return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b private static long lcm(long a, long b) {
    return a / gcd(a, b) * b;
  } lcm {
    return a / gcd(a, b) * b;
  } return a / gcd(a, b) * b; a / gcd(a, b) * b a / gcd(a, b) a gcd(a, b) gcd a b 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 lcm = lcm(c, d);
      long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
      long cnt2 = b - b / c - b / d + b / lcm;

      System.out.println(cnt2 - cnt1);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }

  private static long lcm(long a, long b) {
    return a / gcd(a, 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 lcm = lcm(c, d);
      long cnt1 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;
      long cnt2 = b - b / c - b / d + b / lcm;

      System.out.println(cnt2 - cnt1);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }

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

      System.out.println(cnt2 - cnt1);
  }

  private static long gcd(long a, long b) {
    if(b == 0)
      return a;
    return gcd(b, a % b);
  }

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