
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);        
        Long a = stdIn.nextLong();
        Long b = stdIn.nextLong();
        int c = stdIn.nextInt();
        int d = stdIn.nextInt();
        long lcm = LCM(c,d);
        System.out.println((b - a + 1) - ((b/c - (a - 1)/c) +( b/d - (a - 1)/d) - b/lcm + (a - 1)/lcm)); 
    }
    static long LCM(long x, long y){
        if( x < y){
            long t = x;
            x = y;
            y = t;
        }
        return x*y / gcd(x, y);
    }

    private static long gcd(long m, long n){
        if(n == 0) return m;
        else return gcd(n, m % n);
    } 
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz