import java.util.*;

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

public 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 cd = lcm(c,d);
	System.out.print(b-a+1-(b/c - (a-1)/c + b/d - (a-1)/d - b/cd + (a-1)/cd));
    }
    static long gcd(long m, long n) {
	if (m < n) {
	    long tmp = m;
	    m = n;
	    n = tmp;
	}
	long rem = 0;
	while ((rem = m%n) != 0) {
	    m = n;
	    n = rem;
	}
	return n;
    }
    static long lcm(long m, long n) {
	return m * n / gcd(m, n);
    }
}
