import java.util.Scanner;

public class Main {

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

    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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }
    
} import java.util.Scanner; Scanner java.util public class Main {

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

    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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }
    
} Main private static long lcm(long a, long b) {
        long temp;
        long c = a * b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } lcm {
        long temp;
        long c = a * b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } long temp; temp long c = a * b; c a * b a 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 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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(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 long lcm = lcm(c, d); lcm lcm(c, d) lcm c d long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm); ans b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm) b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d) b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d) b - a + 1 b - a b a 1 (b / c - (a - 1) / c) b / c b c (a - 1) / c (a - 1) a 1 c (b / d - (a - 1) / d) b / d b d (a - 1) / d (a - 1) a 1 d (b / lcm - (a - 1) / lcm) b / lcm b lcm (a - 1) / lcm (a - 1) a 1 lcm System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

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

    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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }
    
} public class Main {

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

    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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }
    
} Main
import java.util.Scanner;

public class Main {

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

    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 lcm = lcm(c, d);
        long ans = b - a + 1
                - (b / c - (a - 1) / c)
                - (b / d - (a - 1) / d)
                + (b / lcm - (a - 1) / lcm);
        System.out.println(ans);
    }
    
}
