import java.util.Scanner;

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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


} import java.util.Scanner; Scanner 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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


} 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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    } 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 CD = C*D/gcd(C,D); CD C*D/gcd(C,D) C*D C D gcd(C,D) gcd C D long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD ); ans B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD ) B -B/C - B/D + B/CD B -B/C - B/D B -B/C - B/D B B/C B C B/D B D B/CD B CD ( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD ) A-1 -(A-1)/C- (A-1)/D (A-1)/C A-1 -(A-1)/C- (A-1)/D A 1 (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/CD (A-1) A 1 CD System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    } gcd {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    } if (a == 0)
            return b; a == 0 a 0 return b; b return gcd(b % a, a); gcd(b % a, a) gcd b % a b a a long a a long b b 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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


} 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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


} Main
import java.util.Scanner;

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 CD = C*D/gcd(C,D);
        long ans = B -B/C - B/D + B/CD -( A-1 -(A-1)/C- (A-1)/D+(A-1)/CD );
        System.out.println(ans);

//        System.out.println(gcd(15L,20L));
    }

    static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }


}
