import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    }

    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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    }

    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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    } main {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() - 1; a sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 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 x = lcm(c, d); x lcm(c, d) lcm c d long modB = b - b / c - b / d + b / x; modB b - b / c - b / d + b / x b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / x b x long modA = a - a / c - a / d + a / x; modA a - a / c - a / d + a / x a - a / c - a / d a - a / c - a / d a a / c a c a / d a d a / x a x System.out.println(modB - modA) System.out.println System.out System System.out modB - modA modB modA 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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    }

    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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    }

    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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long x = lcm(c, d);

        long modB = b - b / c - b / d + b / x;
        long modA = a - a / c - a / d + a / x;

        System.out.println(modB - modA);

    }

    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;
    }

}
