import java.util.*;
import java.math.*;

public class Main {

    static long MOD = 1000000007;

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

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


    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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
} import java.util.*; util.* java import java.math.*; math.* java public class Main {

    static long MOD = 1000000007;

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

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


    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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
} Main static long MOD = 1000000007; MOD 1000000007 public 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; a return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b long a a long b b public 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 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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    } 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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d))); ans (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d))) (b - a + 1) b - a b a 1 ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d))) (b / d + b / c - b / lcm(c,d)) b / d + b / c b / d b d b / c b c b / lcm(c,d) b lcm(c,d) lcm c d ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)) (a-1) / d + (a-1) / c (a-1) / d (a-1) a 1 d (a-1) / c (a-1) a 1 c (a-1) / lcm(c,d) (a-1) a 1 lcm(c,d) lcm c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    static long MOD = 1000000007;

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

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


    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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
} public class Main {

    static long MOD = 1000000007;

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

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


    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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
} Main
import java.util.*;
import java.math.*;

public class Main {

    static long MOD = 1000000007;

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

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


    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 ans = (b - a + 1) - ((b / d + b / c - b / lcm(c,d)) - ((a-1) / d + (a-1) / c - (a-1) / lcm(c,d)));
        System.out.println(ans);
    }
}