import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
        long c = B / C - (A - 1) / C;
        long d = B / D - (A - 1) / D;
        long e = B / lcm - (A - 1) / lcm;
        long ans = B - A + 1 - c - d + e; 
        System.out.println(ans);
    }
    public static long gcd(long max, long min){
        if(max%min==0){
            return min;
        }
        min = gcd(min, max % min);
        return min;
    }
} import java.util.*; util.* java import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.HashMap; HashMap java.util class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
        long c = B / C - (A - 1) / C;
        long d = B / D - (A - 1) / D;
        long e = B / lcm - (A - 1) / lcm;
        long ans = B - A + 1 - c - d + e; 
        System.out.println(ans);
    }
    public static long gcd(long max, long min){
        if(max%min==0){
            return min;
        }
        min = gcd(min, max % min);
        return min;
    }
} Main public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
        long c = B / C - (A - 1) / C;
        long d = B / D - (A - 1) / D;
        long e = B / lcm - (A - 1) / lcm;
        long ans = B - A + 1 - c - d + e; 
        System.out.println(ans);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
        long c = B / C - (A - 1) / C;
        long d = B / D - (A - 1) / D;
        long e = B / lcm - (A - 1) / lcm;
        long ans = B - A + 1 - c - d + e; 
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D)); lcm C * D / gcd(Math.max(C, D), Math.min(C, D)) C * D C D gcd(Math.max(C, D), Math.min(C, D)) gcd Math.max(C, D) Math.max Math C D Math.min(C, D) Math.min Math C D long c = B / C - (A - 1) / C; c B / C - (A - 1) / C B / C B C (A - 1) / C (A - 1) A 1 C long d = B / D - (A - 1) / D; d B / D - (A - 1) / D B / D B D (A - 1) / D (A - 1) A 1 D long e = B / lcm - (A - 1) / lcm; e B / lcm - (A - 1) / lcm B / lcm B lcm (A - 1) / lcm (A - 1) A 1 lcm long ans = B - A + 1 - c - d + e; ans B - A + 1 - c - d + e B - A + 1 - c - d B - A + 1 - c - d B - A + 1 B - A B A 1 c d e System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long gcd(long max, long min){
        if(max%min==0){
            return min;
        }
        min = gcd(min, max % min);
        return min;
    } gcd {
        if(max%min==0){
            return min;
        }
        min = gcd(min, max % min);
        return min;
    } if(max%min==0){
            return min;
        } max%min==0 max%min max min 0 {
            return min;
        } return min; min min = gcd(min, max % min) min gcd(min, max % min) gcd min max % min max min return min; min long max max long min min
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        long lcm = C * D / gcd(Math.max(C, D), Math.min(C, D));
        long c = B / C - (A - 1) / C;
        long d = B / D - (A - 1) / D;
        long e = B / lcm - (A - 1) / lcm;
        long ans = B - A + 1 - c - d + e; 
        System.out.println(ans);
    }
    public static long gcd(long max, long min){
        if(max%min==0){
            return min;
        }
        min = gcd(min, max % min);
        return min;
    }
}