import java.util.*;


class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    }
} import java.util.*; util.* java class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    }
} Main static long mod = 1000000007; mod 1000000007 public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc final long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc final long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc final long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long count=B-A+1; count B-A+1 B-A B A 1 count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C) count count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C) count (A%C == 0 ? B/C - A/C + 1 : B/C - A/C) A%C == 0 A%C A C 0 B/C - A/C + 1 B/C - A/C B/C B C A/C A C 1 B/C - A/C B/C B C A/C A C count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D) count count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D) count (A%D == 0 ? B/D - A/D + 1 : B/D - A/D) A%D == 0 A%D A D 0 B/D - A/D + 1 B/D - A/D B/D B D A/D A D 1 B/D - A/D B/D B D A/D A D long mi = Math.min(C, D); mi Math.min(C, D) Math.min Math C D long ma = Math.max(C, D); ma Math.max(C, D) Math.max Math C D long tmp = 0; tmp 0 while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        } (tmp=ma%mi)!=0 (tmp=ma%mi) tmp ma%mi ma mi 0 {
            ma = mi;
            mi = tmp;
        } ma = mi ma mi mi = tmp mi tmp long CD = C*D/mi; CD C*D/mi C*D C D mi count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD) count count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD) count (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD) A%CD == 0 A%CD A CD 0 B/CD - A/CD + 1 B/CD - A/CD B/CD B CD A/CD A CD 1 B/CD - A/CD B/CD B CD A/CD A CD System.out.println(count) System.out.println System.out System System.out count String argv[] argv
import java.util.*;


class Main{
    static long mod = 1000000007;
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        long count=B-A+1;

        count = count - (A%C == 0 ? B/C - A/C + 1 : B/C - A/C);
        count = count - (A%D == 0 ? B/D - A/D + 1 : B/D - A/D);
        long mi = Math.min(C, D);
        long ma = Math.max(C, D);
        long tmp = 0;
        while((tmp=ma%mi)!=0){
            ma = mi;
            mi = tmp;
        }
        long CD = C*D/mi;
        count = count + (A%CD == 0 ? B/CD - A/CD + 1 : B/CD - A/CD);
        System.out.println(count);
    }
}