import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    }

    private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    }

    private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    } main {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner long all = b - a + 1; all b - a + 1 b - a b a 1 long canDivC=b/ c - a/ c ; canDivC b/ c - a/ c b/ c b c a/ c a c long canDivD=b/ d - a/ d ; canDivD b/ d - a/ d b/ d b d a/ d a d long canDivCD= b/ lcm(c,d) - a/ lcm(c,d); canDivCD b/ lcm(c,d) - a/ lcm(c,d) b/ lcm(c,d) b lcm(c,d) lcm c d a/ lcm(c,d) a lcm(c,d) lcm c d if (a % c == 0) {
            canDivC++;
        } a % c == 0 a % c a c 0 {
            canDivC++;
        } canDivC++ canDivC if (a % d == 0) {
            canDivD++;
        } a % d == 0 a % d a d 0 {
            canDivD++;
        } canDivD++ canDivD if (a % (c * d) == 0) {
            canDivCD++;
        } a % (c * d) == 0 a % (c * d) a (c * d) c d 0 {
            canDivCD++;
        } canDivCD++ canDivCD System.out.println(all - canDivC - canDivD + canDivCD) System.out.println System.out System System.out all - canDivC - canDivD + canDivCD all - canDivC - canDivD all - canDivC - canDivD all canDivC canDivD canDivCD String[] args args private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        } lcm {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        } long temp; temp long c = a; c a c *= b c b 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 (long)(c/b); (long)(c/b) c b long a a long b b public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    }

    private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    }

    private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long all = b - a + 1;
        long canDivC=b/ c - a/ c ;
        long canDivD=b/ d - a/ d ;
        long canDivCD= b/ lcm(c,d) - a/ lcm(c,d);
        if (a % c == 0) {
            canDivC++;
        }
        if (a % d == 0) {
            canDivD++;
        }
        if (a % (c * d) == 0) {
            canDivCD++;
        }
        System.out.println(all - canDivC - canDivD + canDivCD);
    }

    private static long lcm(long a, long b) {
            long temp;
            long c = a;
            c *= b;
            while((temp = a%b)!=0) {
                a = b;
                b = temp;
            }
            return (long)(c/b);

        }
}