import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    }

    public static long gcd(long a, long b){
        if(b == 0){return a;}
        return gcd(b, a%b);
    }
}
 import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    }

    public static long gcd(long a, long b){
        if(b == 0){return a;}
        return gcd(b, a%b);
    }
} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    } main {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))); count b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))) b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))) b/c + b/d b/c b c b/d b d b/(c * d / gcd(c,d)) b (c * d / gcd(c,d)) c * d c d gcd(c,d) gcd c d ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))) (a-1)/c + (a-1)/d (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/(c * d / gcd(c,d)) (a-1) a 1 (c * d / gcd(c,d)) c * d c d gcd(c,d) gcd c d System.out.println((b-a+1-count)) System.out.println System.out System System.out (b-a+1-count) b-a+1 b-a b a 1 count String[] args args 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;} return a; a return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b long a a long b b
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long count = b/c + b/d - b/(c * d / gcd(c,d)) - ((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d)));
        //System.out.println(b/c + b/d - b/(c * d / gcd(c,d)));
        //System.out.println(((a-1)/c + (a-1)/d - (a-1)/(c * d / gcd(c,d))));
        System.out.println((b-a+1-count));
        
    }

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

