
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);
    } 
} import java.util.*; util.* java 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);
    } 
} 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)); 
    } main {
        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)); 
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) 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 long lcm = LCM(c,d); lcm LCM(c,d) LCM c d System.out.println((b - a + 1) - ((b/c - (a - 1)/c) +( b/d - (a - 1)/d) - b/lcm + (a - 1)/lcm)) System.out.println System.out System System.out (b - a + 1) - ((b/c - (a - 1)/c) +( b/d - (a - 1)/d) - b/lcm + (a - 1)/lcm) (b - a + 1) b - a b a 1 ((b/c - (a - 1)/c) +( b/d - (a - 1)/d) - b/lcm + (a - 1)/lcm) (b/c - (a - 1)/c) +( b/d - (a - 1)/d) - b/lcm (b/c - (a - 1)/c) +( b/d - (a - 1)/d) (b/c - (a - 1)/c) b/c b c (a - 1)/c (a - 1) a 1 c ( b/d - (a - 1)/d) b/d b d (a - 1)/d (a - 1) a 1 d b/lcm b lcm (a - 1)/lcm (a - 1) a 1 lcm String[] args args static long LCM(long x, long y){
        if( x < y){
            long t = x;
            x = y;
            y = t;
        }
        return x*y / gcd(x, y);
    } LCM {
        if( x < y){
            long t = x;
            x = y;
            y = t;
        }
        return x*y / gcd(x, y);
    } if( x < y){
            long t = x;
            x = y;
            y = t;
        } x < y x y {
            long t = x;
            x = y;
            y = t;
        } long t = x; t x x = y x y y = t y t return x*y / gcd(x, y); x*y / gcd(x, y) x*y x y gcd(x, y) gcd x y long x x long y y private static long gcd(long m, long n){
        if(n == 0) return m;
        else return gcd(n, m % n);
    } gcd {
        if(n == 0) return m;
        else return gcd(n, m % n);
    } if(n == 0) return m;
        else return gcd(n, m % n); n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n

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);
    } 
}