import java.math.BigInteger;
import java.util.*;

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

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    }

    public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    }
} import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    }

    public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    } main {
        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE); A new BigInteger(sc.next()).subtract(BigInteger.ONE) new BigInteger(sc.next()).subtract new BigInteger(sc.next()) BigInteger.ONE BigInteger BigInteger.ONE BigInteger B = new BigInteger(sc.next()); B new BigInteger(sc.next()) BigInteger C = new BigInteger(sc.next()); C new BigInteger(sc.next()) BigInteger D = new BigInteger(sc.next()); D new BigInteger(sc.next()) BigInteger lcm = C.multiply(D).divide(gcd(C, D)); lcm C.multiply(D).divide(gcd(C, D)) C.multiply(D).divide C.multiply(D) C.multiply C D gcd(C, D) gcd C D BigInteger x = B.divide(C).subtract(A.divide(C)); x B.divide(C).subtract(A.divide(C)) B.divide(C).subtract B.divide(C) B.divide B C A.divide(C) A.divide A C BigInteger y = B.divide(D).subtract(A.divide(D)); y B.divide(D).subtract(A.divide(D)) B.divide(D).subtract B.divide(D) B.divide B D A.divide(D) A.divide A D BigInteger z = B.divide(lcm).subtract(A.divide(lcm)); z B.divide(lcm).subtract(A.divide(lcm)) B.divide(lcm).subtract B.divide(lcm) B.divide B lcm A.divide(lcm) A.divide A lcm System.out.println(B.subtract(A).subtract(x.add(y).subtract(z))) System.out.println System.out System System.out B.subtract(A).subtract(x.add(y).subtract(z)) B.subtract(A).subtract B.subtract(A) B.subtract B A x.add(y).subtract(z) x.add(y).subtract x.add(y) x.add x y z String[] args args public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    } gcd {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    } BigInteger temp; temp while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        } !m.mod(n).equals(BigInteger.ZERO) m.mod(n).equals(BigInteger.ZERO) m.mod(n).equals m.mod(n) m.mod m n BigInteger.ZERO BigInteger BigInteger.ZERO {
            temp = n;
            n = m.mod(n);
            m = temp;
        } temp = n temp n n = m.mod(n) n m.mod(n) m.mod m n m = temp m temp return n; n BigInteger m m BigInteger n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    }

    public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    }

    public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    }
} Main
import java.math.BigInteger;
import java.util.*;

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

        BigInteger A = new BigInteger(sc.next()).subtract(BigInteger.ONE);
        BigInteger B = new BigInteger(sc.next());
        BigInteger C = new BigInteger(sc.next());
        BigInteger D = new BigInteger(sc.next());

        BigInteger lcm = C.multiply(D).divide(gcd(C, D));
        BigInteger x = B.divide(C).subtract(A.divide(C));
        BigInteger y = B.divide(D).subtract(A.divide(D));
        BigInteger z = B.divide(lcm).subtract(A.divide(lcm));

        System.out.println(B.subtract(A).subtract(x.add(y).subtract(z)));
    }

    public static BigInteger gcd(BigInteger m, BigInteger n)
    {
        BigInteger temp;
        while (!m.mod(n).equals(BigInteger.ZERO))
        {
            temp = n;
            n = m.mod(n);
            m = temp;
        }
        return n;
    }
}