
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);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util 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);
    }
} 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)));
    } main {
        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)));
    } final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) final long a = in.nextLong(); a in.nextLong() in.nextLong in final long b = in.nextLong(); b in.nextLong() in.nextLong in final long c = in.nextLong(); c in.nextLong() in.nextLong in final long d = in.nextLong(); d in.nextLong() in.nextLong in final long gcd = gcd(c, d); gcd gcd(c, d) gcd c d final long target = (c / gcd) * (d / gcd) * gcd; target (c / gcd) * (d / gcd) * gcd (c / gcd) * (d / gcd) * gcd (c / gcd) c gcd (d / gcd) d gcd gcd final long c1 = (a - 1) / c; c1 (a - 1) / c (a - 1) a 1 c final long c2 = b / c; c2 b / c b c final long d1 = (a - 1) / d; d1 (a - 1) / d (a - 1) a 1 d final long d2 = b / d; d2 b / d b d final long t1 = (a - 1) / target; t1 (a - 1) / target (a - 1) a 1 target final long t2 = b / target; t2 b / target b target System.out.println(b - a + 1 - ((c2 - c1) + (d2 - d1) - (t2 - t1))) System.out.println System.out System System.out b - a + 1 - ((c2 - c1) + (d2 - d1) - (t2 - t1)) b - a + 1 b - a b a 1 ((c2 - c1) + (d2 - d1) - (t2 - t1)) (c2 - c1) + (d2 - d1) (c2 - c1) c2 c1 (d2 - d1) d2 d1 (t2 - t1) t2 t1 String[] args args 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);
    } gcd {
        if (d > c) {
            return gcd(d, c);
        }

        final long mod = c % d;
        if (mod == 0) {
            return d;
        }
        return gcd(d, mod);
    } if (d > c) {
            return gcd(d, c);
        } d > c d c {
            return gcd(d, c);
        } return gcd(d, c); gcd(d, c) gcd d c final long mod = c % d; mod c % d c d if (mod == 0) {
            return d;
        } mod == 0 mod 0 {
            return d;
        } return d; d return gcd(d, mod); gcd(d, mod) gcd d mod long c c long d d 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);
    }
} 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);
    }
} Main

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