import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    }

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

    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    }

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

    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.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 long sum = 0; sum 0 sum += b / c + b / d - b / lcm(c, d) sum b / c + b / d - b / lcm(c, d) b / c + b / d b / c b c b / d b d b / lcm(c, d) b lcm(c, d) lcm c d sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d) sum (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d) (a - 1) / c + (a - 1) / d (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / lcm(c, d) (a - 1) a 1 lcm(c, d) lcm c d System.out.println((b - a + 1) - sum) System.out.println System.out System System.out (b - a + 1) - sum (b - a + 1) b - a b a 1 sum String[] args args static long lcm(long a, long b) {
        long gcd = gcd(a, b);
        return a / gcd * b;
    } lcm {
        long gcd = gcd(a, b);
        return a / gcd * b;
    } long gcd = gcd(a, b); gcd gcd(a, b) gcd a b return a / gcd * b; a / gcd * b a / gcd a gcd b long a a long b b static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } gcd {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    } if (b == 0) {
            return a;
        } b == 0 b 0 {
            return a;
        } return a; 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) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    }

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

    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    }

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

    static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} Main
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long sum = 0;
        sum += b / c + b / d - b / lcm(c, d);
        sum -= (a - 1) / c + (a - 1) / d - (a - 1) / lcm(c, d);
        System.out.println((b - a + 1) - sum);
    }

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

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