
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
} import java.util.*; util.* java public class Main {

    private static final int INF = Integer.MAX_VALUE;

    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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
} Main private static final int INF = Integer.MAX_VALUE; INF Integer.MAX_VALUE Integer Integer.MAX_VALUE 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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    } 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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    } 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 = lcm(c, d); lcm lcm(c, d) lcm c d long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm; result (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm (b-a+1)-b/c+(a-1)/c-b/d (b-a+1)-b/c+(a-1)/c (b-a+1)-b/c (b-a+1) b-a b a 1 b/c b c (a-1)/c (a-1) a 1 c b/d b d (a-1)/d (a-1) a 1 d b/lcm b lcm (a-1)/lcm (a-1) a 1 lcm System.out.println(result) System.out.println System.out System System.out result String[] args args //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; 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 private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    } lcm {
        return m * n / gcd(m, n);
    } return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n public class Main {

    private static final int INF = Integer.MAX_VALUE;

    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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
} public class Main {

    private static final int INF = Integer.MAX_VALUE;

    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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
} Main

import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    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 = lcm(c, d);
        
        long result = (b-a+1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm-(a-1)/lcm;

        System.out.println(result);

    }

    //最大公約数
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
}
