import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    }
    static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    }
    static long lcm(long a, long b){
        return a * b / gcd(a, b);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    }
    static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    }
    static long lcm(long a, long b){
        return a * b / gcd(a, b);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan long b = scan.nextLong(); b scan.nextLong() scan.nextLong scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int d = scan.nextInt(); d scan.nextInt() scan.nextInt scan long lcm = lcm(c, d); lcm lcm(c, d) lcm c d System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm) System.out.println System.out System System.out b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d (a - 1) / c b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d b - b / c - b / d + b / lcm - a b - b / c - b / d + b / lcm b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / lcm b lcm a 1 (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / lcm (a - 1) a 1 lcm scan.close() scan.close scan String[] args args static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    } gcd {
        return b > 0 ? gcd(b, a % b) : a;
    } return b > 0 ? gcd(b, a % b) : a; b > 0 ? gcd(b, a % b) : a b > 0 b 0 gcd(b, a % b) gcd b a % b a b a long a a long b b 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 public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    }
    static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    }
    static long lcm(long a, long b){
        return a * b / gcd(a, b);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    }
    static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    }
    static long lcm(long a, long b){
        return a * b / gcd(a, b);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = scan.nextLong();
        long b = scan.nextLong();
        int c = scan.nextInt();
        int d = scan.nextInt();
        long lcm = lcm(c, d);
        System.out.println(b - b / c - b / d + b / lcm - a + 1 + (a - 1) / c + (a - 1) / d - (a - 1) / lcm);
        scan.close();
    }
    static long gcd(long a, long b){
        return b > 0 ? gcd(b, a % b) : a;
    }
    static long lcm(long a, long b){
        return a * b / gcd(a, b);
    }
}
