
import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  }
    
  static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  }

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

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  }
    
  static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  }

  static long lcm(long a, long b) {
    
    return a * b / gcd(a, b);
  }
} Main /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  } main {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long cMulti = (b / c) - ((a - 1) / c); cMulti (b / c) - ((a - 1) / c) (b / c) b c ((a - 1) / c) (a - 1) a 1 c long dMulti = (b / d) - ((a - 1) / d); dMulti (b / d) - ((a - 1) / d) (b / d) b d ((a - 1) / d) (a - 1) a 1 d long lcm = lcm(c, d); lcm lcm(c, d) lcm c d System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm)) System.out.println System.out System System.out b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm) b - a + 1 - cMulti - dMulti + b / lcm b - a + 1 - cMulti - dMulti b - a + 1 - cMulti - dMulti b - a + 1 b - a b a 1 cMulti dMulti b / lcm b lcm ((a - 1) / lcm) (a - 1) a 1 lcm String[] args args static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  } gcd {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  } long c = 0; c 0 do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0); c != 0 c 0 {
      c = a % b;
      a = b;
      b = c;
    } c = a % b c a % b a b a = b a b b = c b c return a; a long a a long b b 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 {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  }
    
  static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  }

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

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  }
    
  static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  }

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

import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long c = Long.parseLong(sc.next());
    long d = Long.parseLong(sc.next());

 //   System.out
 //       .println(
 //           LongStream.range(a, b + 1).filter(i -> i % c != 0 && i % d != 0).count());
 // }

    long cMulti = (b / c) - ((a - 1) / c);
    long dMulti = (b / d) - ((a - 1) / d);
    long lcm = lcm(c, d);
    System.out.println(b - a + 1 - cMulti - dMulti + b / lcm - ((a - 1) / lcm));
  }
    
  static long gcd(long a, long b) {
    
    long c = 0;
    do {
      c = a % b;
      a = b;
      b = c;
    } while (c != 0);
    return a;
  }

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