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.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    }
} 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.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    } 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.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long p = d p d q = c; q c while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        } p % q != 0 p % q p q 0 {
            long m = q;
            q = p % q;
            p = m;
        } long m = q; m q q = p % q q p % q p q p = m p m long l = (c * d) / q; l (c * d) / q (c * d) c d q long counter_b = b - (b / c) - (b / d) + (b / l); counter_b b - (b / c) - (b / d) + (b / l) b - (b / c) - (b / d) b - (b / c) - (b / d) b (b / c) b c (b / d) b d (b / l) b l long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l); counter_a (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l) (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) / l) (a - 1) a 1 l System.out.println(counter_b - counter_a) System.out.println System.out System System.out counter_b - counter_a counter_b counter_a sc.close() sc.close sc String[] args args 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.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    }
} 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.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    }
} 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.nextLong();
        long d = sc.nextLong();
        long p = d, q = c;
        while (p % q != 0) {
            long m = q;
            q = p % q;
            p = m;
        }
        long l = (c * d) / q;
        long counter_b = b - (b / c) - (b / d) + (b / l);
        long counter_a = (a - 1) - ((a - 1) / c) - ((a - 1) / d) + ((a - 1) / l);
        System.out.println(counter_b - counter_a);
        sc.close();
    }
}