import 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 numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    }


    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return c/b;
    }
} import java.util.*; util.* java 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 numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    }


    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return c/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();

        long numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    } 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 numC = b / c - (a - 1) / c; numC b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long numD = b / d - (a - 1) / d; numD b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long l = lcm(c, d); l lcm(c, d) lcm c d long numL = b / l - (a - 1) / l; numL b / l - (a - 1) / l b / l b l (a - 1) / l (a - 1) a 1 l System.out.print(b - a - (numC + numD - numL) + 1) System.out.print System.out System System.out b - a - (numC + numD - numL) + 1 b - a - (numC + numD - numL) b - a - (numC + numD - numL) b a (numC + numD - numL) numC + numD numC numD numL 1 String[] args args static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return c/b;
    } lcm {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return 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 c/b; c/b c b 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 numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    }


    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return c/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 numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    }


    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return c/b;
    }
} Main
import 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 numC = b / c - (a - 1) / c;
        long numD = b / d - (a - 1) / d;

        long l = lcm(c, d);
        long numL = b / l - (a - 1) / l;

        System.out.print(b - a - (numC + numD - numL) + 1);
    }


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