import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }

} Main public static void main(String[] args) {
        solve();
    } main {
        solve();
    } solve() solve String[] args args private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    } solve {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    } Scanner input = new Scanner(System.in); input new Scanner(System.in) long a = Long.parseLong(input.next()); a Long.parseLong(input.next()) Long.parseLong Long input.next() input.next input long b = Long.parseLong(input.next()); b Long.parseLong(input.next()) Long.parseLong Long input.next() input.next input long c = Long.parseLong(input.next()); c Long.parseLong(input.next()) Long.parseLong Long input.next() input.next input long d = Long.parseLong(input.next()); d Long.parseLong(input.next()) Long.parseLong Long input.next() input.next input long ansA1 = (a - 1) / c; ansA1 (a - 1) / c (a - 1) a 1 c long ansA2 = (a - 1) / d; ansA2 (a - 1) / d (a - 1) a 1 d long ansA3 = (a - 1) / lcm(c, d); ansA3 (a - 1) / lcm(c, d) (a - 1) a 1 lcm(c, d) lcm c d long ansB1 = b / c; ansB1 b / c b c long ansB2 = b / d; ansB2 b / d b d long ansB3 = b / lcm(c, d); ansB3 b / lcm(c, d) b lcm(c, d) lcm c d long ansB = ansB1 + ansB2 - ansB3; ansB ansB1 + ansB2 - ansB3 ansB1 + ansB2 ansB1 ansB2 ansB3 long ansA = ansA1 + ansA2 - ansA3; ansA ansA1 + ansA2 - ansA3 ansA1 + ansA2 ansA1 ansA2 ansA3 long ans = ansB - ansA; ans ansB - ansA ansB ansA long result = b - (a - 1) - ans; result b - (a - 1) - ans b - (a - 1) - ans b (a - 1) a 1 ans System.out.println(result) System.out.println System.out System System.out result static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    } lcm {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    } long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	} (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
    		a = b;
    		b = temp;
    	} a = b a b b = temp b temp return (c/b); (c/b) c b long a a long b b public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }

} public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        solve();
    }

    private static void solve() {
        Scanner input = new Scanner(System.in);

        long a = Long.parseLong(input.next());
        long b = Long.parseLong(input.next());
        long c = Long.parseLong(input.next());
        long d = Long.parseLong(input.next());

        long ansA1 = (a - 1) / c;
        long ansA2 = (a - 1) / d;
        long ansA3 = (a - 1) / lcm(c, d);

        long ansB1 = b / c;
        long ansB2 = b / d;
        long ansB3 = b / lcm(c, d);

        long ansB = ansB1 + ansB2 - ansB3;
        long ansA = ansA1 + ansA2 - ansA3;

        long ans = ansB - ansA;
        long result = b - (a - 1) - ans;

        System.out.println(result);

    }

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }

}
