
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final long a = in.nextLong();
        final long b = in.nextLong();
        final long c = in.nextLong();
        final long d = in.nextLong();

        final long gcd = gcd(c, d);
        final long target = (c / gcd) * (d / gcd) * gcd;

        final long c1 = (a - 1) / c;
        final long c2 = b / c;

        final long d1 = (a - 1) / d;
        final long d2 = b / d;

        final long t1 = (a - 1) / target;
        final long t2 = b / target;
        System.out.println(b - a + 1 - ((c2 - c1) + (d2 - d1) - (t2 - t1)));
    }

    private static long gcd(long c, long d) {
        if (d > c) {
            return gcd(d, c);
        }

        final long mod = c % d;
        if (mod == 0) {
            return d;
        }
        return gcd(d, mod);
    }
}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz