import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    } 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 divc = b/c - (a-1)/c; divc b/c - (a-1)/c b/c b c (a-1)/c (a-1) a 1 c long divd = b/d - (a-1)/d; divd b/d - (a-1)/d b/d b d (a-1)/d (a-1) a 1 d long lcmcd = lcm(c,d); lcmcd lcm(c,d) lcm c d long divcd = b/lcmcd - (a-1)/lcmcd; divcd b/lcmcd - (a-1)/lcmcd b/lcmcd b lcmcd (a-1)/lcmcd (a-1) a 1 lcmcd System.out.println((b-a+1) - divc - divd + divcd) System.out.println System.out System System.out (b-a+1) - divc - divd + divcd (b-a+1) - divc - divd (b-a+1) - divc - divd (b-a+1) b-a b a 1 divc divd divcd String[] args args private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    } gcd {
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    } while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        } b > 0 b 0 {
            long temp = b;
            b = a % b; 
            a = temp;
        } long temp = b; temp b b = a % b b a % b a b a = temp a temp return a; a long a a long b b private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    } lcm {
        return a * (b / gcd(a, b));
    } return a * (b / gcd(a, b)); a * (b / gcd(a, b)) a (b / gcd(a, b)) b gcd(a, b) gcd a b long a a long b b public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
} Main
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long divc = b/c - (a-1)/c;
        long divd = b/d - (a-1)/d;
        long lcmcd = lcm(c,d);
        long divcd = b/lcmcd - (a-1)/lcmcd;
        System.out.println((b-a+1) - divc - divd + divcd);
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; 
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }
}
