import java.util.*;

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 ans = num(b, c, d) - num(a-1, c, d);
        System.out.println(ans);
        
    }

    public static long num(long n, long c, long d) {
        long G = gcd(c, d);
        long L = c / G * d;
        return n - n / c - n / d + n / L;
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} import java.util.*; util.* java 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 ans = num(b, c, d) - num(a-1, c, d);
        System.out.println(ans);
        
    }

    public static long num(long n, long c, long d) {
        long G = gcd(c, d);
        long L = c / G * d;
        return n - n / c - n / d + n / L;
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} 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 ans = num(b, c, d) - num(a-1, c, d);
        System.out.println(ans);
        
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long ans = num(b, c, d) - num(a-1, c, d);
        System.out.println(ans);
        
    } 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 ans = num(b, c, d) - num(a-1, c, d); ans num(b, c, d) - num(a-1, c, d) num(b, c, d) num b c d num(a-1, c, d) num a-1 a 1 c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long num(long n, long c, long d) {
        long G = gcd(c, d);
        long L = c / G * d;
        return n - n / c - n / d + n / L;
    } num {
        long G = gcd(c, d);
        long L = c / G * d;
        return n - n / c - n / d + n / L;
    } long G = gcd(c, d); G gcd(c, d) gcd c d long L = c / G * d; L c / G * d c / G c G d return n - n / c - n / d + n / L; n - n / c - n / d + n / L n - n / c - n / d n - n / c - n / d n n / c n c n / d n d n / L n L long n n long c c long d d private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n
import java.util.*;

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 ans = num(b, c, d) - num(a-1, c, d);
        System.out.println(ans);
        
    }

    public static long num(long n, long c, long d) {
        long G = gcd(c, d);
        long L = c / G * d;
        return n - n / c - n / d + n / L;
    }
    
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}