import java.util.*;
import java.lang.*;

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();

        sc.close();
        long ans = 0;
        long g = (C*D) / gcd(C,D);
       // System.out.println(g);
        ans += ((B/C) - ((A-1)/C));        
       // System.out.println(ans);
        ans += ((B/D) - ((A-1)/D));
       // System.out.println(ans);
        ans -= ((B/g) - ((A-1)/g));

        System.out.println((B-A+1) - ans);

    }
    static long gcd (long a, long b){
        long temp;
        while((temp = a%b) != 0){
            a = b;
            b = temp;
        }
        return b;
    }
} import java.util.*; util.* java import java.lang.*; lang.* 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();

        sc.close();
        long ans = 0;
        long g = (C*D) / gcd(C,D);
       // System.out.println(g);
        ans += ((B/C) - ((A-1)/C));        
       // System.out.println(ans);
        ans += ((B/D) - ((A-1)/D));
       // System.out.println(ans);
        ans -= ((B/g) - ((A-1)/g));

        System.out.println((B-A+1) - ans);

    }
    static long gcd (long a, long b){
        long temp;
        while((temp = a%b) != 0){
            a = b;
            b = temp;
        }
        return 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.nextLong();
        long D = sc.nextLong();

        sc.close();
        long ans = 0;
        long g = (C*D) / gcd(C,D);
       // System.out.println(g);
        ans += ((B/C) - ((A-1)/C));        
       // System.out.println(ans);
        ans += ((B/D) - ((A-1)/D));
       // System.out.println(ans);
        ans -= ((B/g) - ((A-1)/g));

        System.out.println((B-A+1) - ans);

    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        sc.close();
        long ans = 0;
        long g = (C*D) / gcd(C,D);
       // System.out.println(g);
        ans += ((B/C) - ((A-1)/C));        
       // System.out.println(ans);
        ans += ((B/D) - ((A-1)/D));
       // System.out.println(ans);
        ans -= ((B/g) - ((A-1)/g));

        System.out.println((B-A+1) - 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 sc.close() sc.close sc long ans = 0; ans 0 long g = (C*D) / gcd(C,D); g (C*D) / gcd(C,D) (C*D) C D gcd(C,D) gcd C D ans += ((B/C) - ((A-1)/C)) ans ((B/C) - ((A-1)/C)) (B/C) B C ((A-1)/C) (A-1) A 1 C ans += ((B/D) - ((A-1)/D)) ans ((B/D) - ((A-1)/D)) (B/D) B D ((A-1)/D) (A-1) A 1 D ans -= ((B/g) - ((A-1)/g)) ans ((B/g) - ((A-1)/g)) (B/g) B g ((A-1)/g) (A-1) A 1 g System.out.println((B-A+1) - ans) System.out.println System.out System System.out (B-A+1) - ans (B-A+1) B-A B A 1 ans String[] args args static long gcd (long a, long b){
        long temp;
        while((temp = a%b) != 0){
            a = b;
            b = temp;
        }
        return b;
    } gcd {
        long temp;
        while((temp = a%b) != 0){
            a = b;
            b = temp;
        }
        return b;
    } long temp; temp while((temp = a%b) != 0){
            a = b;
            b = temp;
        } (temp = a%b) != 0 (temp = a%b) temp a%b a b 0 {
            a = b;
            b = temp;
        } a = b a b b = temp b temp return b; b long a a long b b
import java.util.*;
import java.lang.*;

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();

        sc.close();
        long ans = 0;
        long g = (C*D) / gcd(C,D);
       // System.out.println(g);
        ans += ((B/C) - ((A-1)/C));        
       // System.out.println(ans);
        ans += ((B/D) - ((A-1)/D));
       // System.out.println(ans);
        ans -= ((B/g) - ((A-1)/g));

        System.out.println((B-A+1) - ans);

    }
    static long gcd (long a, long b){
        long temp;
        while((temp = a%b) != 0){
            a = b;
            b = temp;
        }
        return b;
    }
}
