import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
} Main public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    } main {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) long a = in.nextLong() a in.nextLong() in.nextLong in b = in.nextLong() b in.nextLong() in.nextLong in c = in.nextLong() c in.nextLong() in.nextLong in d = in.nextLong(); d in.nextLong() in.nextLong in long gcd = gcd(c, d); gcd gcd(c, d) gcd c d long right = b - (b/c + b/d) + (b/(c * d/gcd)); right b - (b/c + b/d) + (b/(c * d/gcd)) b - (b/c + b/d) b (b/c + b/d) b/c b c b/d b d (b/(c * d/gcd)) b (c * d/gcd) c * d c d gcd long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd)); left a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd)) a - 1 - (((a - 1) / c) + ((a - 1) / d)) a - 1 - (((a - 1) / c) + ((a - 1) / d)) a 1 (((a - 1) / c) + ((a - 1) / d)) ((a - 1) / c) (a - 1) a 1 c ((a - 1) / d) (a - 1) a 1 d ((a - 1)/(c * d/gcd)) (a - 1) a 1 (c * d/gcd) c * d c d gcd out.println(right - left) out.println out right - left right left out.close() out.close out String[] args args public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    } gcd {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    } if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b); a == 0 || b == 0 a == 0 a 0 b == 0 b 0 return b + a; b + a b a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
} Main
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(System.out);

        long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
        long gcd = gcd(c, d);
        long right = b - (b/c + b/d) + (b/(c * d/gcd));
        long left = a - 1 - (((a - 1) / c) + ((a - 1) / d)) + ((a - 1)/(c * d/gcd));
        out.println(right - left);
        out.close();
    }

    public static long gcd(long a, long b) {
        if (a == 0 || b == 0) return b + a;
        else return gcd(b, a % b);
    }
}