import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    }

    private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
} import java.io.BufferedInputStream; BufferedInputStream java.io import java.io.BufferedOutputStream; BufferedOutputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    }

    private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
} Main public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    } main {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    } try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        } {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        } BufferedInputStream in = new BufferedInputStream(System.in) BufferedInputStream in = new BufferedInputStream(System.in) new BufferedInputStream(System.in) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)) new PrintWriter(new BufferedOutputStream(System.out)) Scanner sc = new Scanner(in); sc new Scanner(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 out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d))) out.println out b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)) b - a + 1 - cnt(a, b, c) - cnt(a, b, d) b - a + 1 - cnt(a, b, c) - cnt(a, b, d) b - a + 1 b - a b a 1 cnt(a, b, c) cnt a b c cnt(a, b, d) cnt a b d cnt(a, b, lcm(c, d)) cnt a b lcm(c, d) lcm c d String[] args args private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    } cnt {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    } long consumed = (a - 1) % c; consumed (a - 1) % c (a - 1) a 1 c long rest = c - 1 - consumed; rest c - 1 - consumed c - 1 - consumed c 1 consumed a += rest a rest return (b - a + 1 + c - 1) / c; (b - a + 1 + c - 1) / c (b - a + 1 + c - 1) b - a + 1 + c b - a + 1 + c b - a b a 1 c 1 c long a a long b b long c c private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    } gcd {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    } while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        } b > 0 b 0 {
            long t = a % b;
            a = b;
            b = t;
        } long t = a % b; t a % b a b a = b a b b = t b t return a; a long a a long b b public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    }

    private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    }

    private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
} Main
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            // 11:47-

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

            out.println(b - a + 1 - cnt(a, b, c) - cnt(a, b, d) + cnt(a, b, lcm(c, d)));

        }
    }

    private static long cnt(long a, long b, long c) {
        long consumed = (a - 1) % c;
        long rest = c - 1 - consumed;
        a += rest;
        return (b - a + 1 + c - 1) / c;
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long t = a % b;
            a = b;
            b = t;
        }
        return a;
    }
}
