import java.util.Scanner;

class LCM {
    static long lcm(int a, int b){
        return (long)a * b / gcd(a, b);
    }

    private static int gcd(int a, int b){
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
}

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	}

	static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	}

	static long division(long n, long d){
		return n / d;
	}
} import java.util.Scanner; Scanner java.util class LCM {
    static long lcm(int a, int b){
        return (long)a * b / gcd(a, b);
    }

    private static int gcd(int a, int b){
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
} LCM static long lcm(int a, int b){
        return (long)a * b / gcd(a, b);
    } lcm {
        return (long)a * b / gcd(a, b);
    } return (long)a * b / gcd(a, b); (long)a * b / gcd(a, b) (long)a * b (long)a b gcd(a, b) gcd a b int a a int b b private static int gcd(int a, int b){
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    } gcd {
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    } if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        } b == 0 b 0 {
            return a;
        } return a; a {
            return gcd(b, a % b);
        } return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b int a a int b b public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	}

	static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	}

	static long division(long n, long d){
		return n / d;
	}
} Main static Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	} main {
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	} long a = stdIn.nextLong(); a stdIn.nextLong() stdIn.nextLong stdIn long b = stdIn.nextLong(); b stdIn.nextLong() stdIn.nextLong stdIn int c = stdIn.nextInt(); c stdIn.nextInt() stdIn.nextInt stdIn int d = stdIn.nextInt(); d stdIn.nextInt() stdIn.nextInt stdIn System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d)) System.out.println System.out System System.out antiDivision(b, c, d) - antiDivision(a-1, c, d) antiDivision(b, c, d) antiDivision b c d antiDivision(a-1, c, d) antiDivision a-1 a 1 c d String[] args args static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	} antiDivision {
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	} return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d))); n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d))) n (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d))) division(n, c) + division(n, d) division(n, c) division n c division(n, d) division n d division(n, LCM.lcm(c, d)) division n LCM.lcm(c, d) LCM.lcm LCM c d long n n int c c int d d static long division(long n, long d){
		return n / d;
	} division {
		return n / d;
	} return n / d; n / d n d long n n long d d public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	}

	static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	}

	static long division(long n, long d){
		return n / d;
	}
} public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	}

	static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	}

	static long division(long n, long d){
		return n / d;
	}
} Main
import java.util.Scanner;

class LCM {
    static long lcm(int a, int b){
        return (long)a * b / gcd(a, b);
    }

    private static int gcd(int a, int b){
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
}

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
		long a = stdIn.nextLong();
		long b = stdIn.nextLong();
		int c = stdIn.nextInt();
		int d = stdIn.nextInt();
		System.out.println(antiDivision(b, c, d) - antiDivision(a-1, c, d));
	}

	static long antiDivision(long n, int c, int d){
		return n - (division(n, c) + division(n, d) - division(n, LCM.lcm(c, d)));
	}

	static long division(long n, long d){
		return n / d;
	}
}
