import java.util.*;

public class Main {
  public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  }

  public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  }
} import java.util.*; util.* java public class Main {
  public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  }

  public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  }
} Main public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  } gcd {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  } long temp_number; temp_number if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    } number_a < number_b number_a number_b {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    } temp_number = number_a temp_number number_a number_a = number_b number_a number_b number_b = temp_number number_b temp_number while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    } (temp_number =number_a % number_b) != 0 (temp_number =number_a % number_b) temp_number number_a % number_b number_a number_b 0 {
      number_a = number_b;
      number_b = temp_number;
    } number_a = number_b number_a number_b number_b = temp_number number_b temp_number return number_b; number_b long number_a number_a long number_b number_b public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  } lcm {
    return (number_a * number_b) / gcd(number_a, number_b);
  } return (number_a * number_b) / gcd(number_a, number_b); (number_a * number_b) / gcd(number_a, number_b) (number_a * number_b) number_a number_b gcd(number_a, number_b) gcd number_a number_b long number_a number_a long number_b number_b public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long start start end end i i number_c number_c number_d number_d number_cd number_cd temp_start temp_start temp_end temp_end count; count long count_c = 1; count_c 1 long count_d = 1; count_d 1 long count_cd = 1; count_cd 1 start = Long.parseLong(sc.next()) start Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc end = Long.parseLong(sc.next()) end Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc number_c = Long.parseLong(sc.next()) number_c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc number_d = Long.parseLong(sc.next()) number_d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc number_cd = lcm(number_c, number_d) number_cd lcm(number_c, number_d) lcm number_c number_d temp_start = start / number_c temp_start start / number_c start number_c temp_end = end / number_c temp_end end / number_c end number_c if(start % number_c != 0) temp_start += 1; start % number_c != 0 start % number_c start number_c 0 temp_start += 1 temp_start 1 count_c += (temp_end - temp_start) count_c (temp_end - temp_start) temp_end temp_start temp_start = start / number_d temp_start start / number_d start number_d temp_end = end / number_d temp_end end / number_d end number_d if(start % number_d != 0) temp_start += 1; start % number_d != 0 start % number_d start number_d 0 temp_start += 1 temp_start 1 count_d += (temp_end - temp_start) count_d (temp_end - temp_start) temp_end temp_start temp_start = start / number_cd temp_start start / number_cd start number_cd temp_end = end / number_cd temp_end end / number_cd end number_cd if(start % number_cd != 0) temp_start += 1; start % number_cd != 0 start % number_cd start number_cd 0 temp_start += 1 temp_start 1 count_cd += (temp_end - temp_start) count_cd (temp_end - temp_start) temp_end temp_start count = (end - start + count_cd + 1) - (count_c + count_d) count (end - start + count_cd + 1) - (count_c + count_d) (end - start + count_cd + 1) end - start + count_cd + 1 end - start end start count_cd 1 (count_c + count_d) count_c count_d System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
  public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  }

  public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  }
} public class Main {
  public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  }

  public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  }
} Main
import java.util.*;

public class Main {
  public static long gcd(long number_a, long number_b) {
    long temp_number;
    if(number_a < number_b) {
      temp_number = number_a;
      number_a = number_b;
      number_b = temp_number;
    }
    while((temp_number =number_a % number_b) != 0) {
      number_a = number_b;
      number_b = temp_number;
    }
    return number_b;
  }

  public static long lcm(long number_a, long number_b) {
    return (number_a * number_b) / gcd(number_a, number_b);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long start, end, i, number_c, number_d, number_cd, temp_start, temp_end, count;
    long count_c = 1;
    long count_d = 1;
    long count_cd = 1;
    start = Long.parseLong(sc.next());
    end = Long.parseLong(sc.next());
    number_c = Long.parseLong(sc.next());
    number_d = Long.parseLong(sc.next());
    number_cd = lcm(number_c, number_d);
    temp_start = start / number_c;
    temp_end = end / number_c;
    if(start % number_c != 0) temp_start += 1;
    count_c += (temp_end - temp_start);

    temp_start = start / number_d;
    temp_end = end / number_d;
    if(start % number_d != 0) temp_start += 1;
    count_d += (temp_end - temp_start);

    temp_start = start / number_cd;
    temp_end = end / number_cd;
    if(start % number_cd != 0) temp_start += 1;
    count_cd += (temp_end - temp_start);
    count = (end - start + count_cd + 1) - (count_c + count_d);
    System.out.println(count);
  }
}
