import java.util.Scanner;
public class Main{
    public static long gcd(long a, long b){
        if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        if(b==0) return a;
        return gcd(b,a%b);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

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

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

        System.out.println(n-m);
    }
} Main public static long gcd(long a, long b){
        if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        if(b==0) return a;
        return gcd(b,a%b);
    } gcd {
        if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        if(b==0) return a;
        return gcd(b,a%b);
    } if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        } a < b a b {
            long tmp = a;
            a = b;
            b = tmp;
        } long tmp = a; tmp a a = b a b b = tmp b tmp if(b==0) return a; b==0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

        System.out.println(n-m);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

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

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

        System.out.println(n-m);
    }
} public class Main{
    public static long gcd(long a, long b){
        if(a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        if(b==0) return a;
        return gcd(b,a%b);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

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

        long lcm = c * d / gcd(c,d);
        long n = b - (b/c) - (b/d) + (b/lcm);
        long m = a - (a/c) - (a/d) + (a/lcm);

        System.out.println(n-m);
    }
}
