import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long sc = scanner.nextLong() - 1;
        long sc2 = scanner.nextLong();
        long sc3 = scanner.nextLong();
        long sc4 = scanner.nextLong();
        long bet = sc2 - sc + 1;
        
        long tmp = sc2/sc3;
        long tmp2 = sc/sc3;
        long minus1 = tmp - tmp2;

        long tmp3 = sc2/sc4;
        long tmp4 = sc/sc4;
        long minus2 = tmp3 - tmp4;
        
        long tmp5 = sc2/lcm(sc3,sc4);
        long tmp6 = sc/lcm(sc3,sc4);
        long minus3 = tmp5 - tmp6;
        long ans = bet - minus1 - minus2 + minus3;
        System.out.println(ans - 1);
    }
    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.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util import java.util.HashSet; HashSet java.util import java.util.List; List java.util class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long sc = scanner.nextLong() - 1;
        long sc2 = scanner.nextLong();
        long sc3 = scanner.nextLong();
        long sc4 = scanner.nextLong();
        long bet = sc2 - sc + 1;
        
        long tmp = sc2/sc3;
        long tmp2 = sc/sc3;
        long minus1 = tmp - tmp2;

        long tmp3 = sc2/sc4;
        long tmp4 = sc/sc4;
        long minus2 = tmp3 - tmp4;
        
        long tmp5 = sc2/lcm(sc3,sc4);
        long tmp6 = sc/lcm(sc3,sc4);
        long minus3 = tmp5 - tmp6;
        long ans = bet - minus1 - minus2 + minus3;
        System.out.println(ans - 1);
    }
    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 public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long sc = scanner.nextLong() - 1;
        long sc2 = scanner.nextLong();
        long sc3 = scanner.nextLong();
        long sc4 = scanner.nextLong();
        long bet = sc2 - sc + 1;
        
        long tmp = sc2/sc3;
        long tmp2 = sc/sc3;
        long minus1 = tmp - tmp2;

        long tmp3 = sc2/sc4;
        long tmp4 = sc/sc4;
        long minus2 = tmp3 - tmp4;
        
        long tmp5 = sc2/lcm(sc3,sc4);
        long tmp6 = sc/lcm(sc3,sc4);
        long minus3 = tmp5 - tmp6;
        long ans = bet - minus1 - minus2 + minus3;
        System.out.println(ans - 1);
    } main {
        Scanner scanner = new Scanner(System.in);
        long sc = scanner.nextLong() - 1;
        long sc2 = scanner.nextLong();
        long sc3 = scanner.nextLong();
        long sc4 = scanner.nextLong();
        long bet = sc2 - sc + 1;
        
        long tmp = sc2/sc3;
        long tmp2 = sc/sc3;
        long minus1 = tmp - tmp2;

        long tmp3 = sc2/sc4;
        long tmp4 = sc/sc4;
        long minus2 = tmp3 - tmp4;
        
        long tmp5 = sc2/lcm(sc3,sc4);
        long tmp6 = sc/lcm(sc3,sc4);
        long minus3 = tmp5 - tmp6;
        long ans = bet - minus1 - minus2 + minus3;
        System.out.println(ans - 1);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long sc = scanner.nextLong() - 1; sc scanner.nextLong() - 1 scanner.nextLong() scanner.nextLong scanner 1 long sc2 = scanner.nextLong(); sc2 scanner.nextLong() scanner.nextLong scanner long sc3 = scanner.nextLong(); sc3 scanner.nextLong() scanner.nextLong scanner long sc4 = scanner.nextLong(); sc4 scanner.nextLong() scanner.nextLong scanner long bet = sc2 - sc + 1; bet sc2 - sc + 1 sc2 - sc sc2 sc 1 long tmp = sc2/sc3; tmp sc2/sc3 sc2 sc3 long tmp2 = sc/sc3; tmp2 sc/sc3 sc sc3 long minus1 = tmp - tmp2; minus1 tmp - tmp2 tmp tmp2 long tmp3 = sc2/sc4; tmp3 sc2/sc4 sc2 sc4 long tmp4 = sc/sc4; tmp4 sc/sc4 sc sc4 long minus2 = tmp3 - tmp4; minus2 tmp3 - tmp4 tmp3 tmp4 long tmp5 = sc2/lcm(sc3,sc4); tmp5 sc2/lcm(sc3,sc4) sc2 lcm(sc3,sc4) lcm sc3 sc4 long tmp6 = sc/lcm(sc3,sc4); tmp6 sc/lcm(sc3,sc4) sc lcm(sc3,sc4) lcm sc3 sc4 long minus3 = tmp5 - tmp6; minus3 tmp5 - tmp6 tmp5 tmp6 long ans = bet - minus1 - minus2 + minus3; ans bet - minus1 - minus2 + minus3 bet - minus1 - minus2 bet - minus1 - minus2 bet minus1 minus2 minus3 System.out.println(ans - 1) System.out.println System.out System System.out ans - 1 ans 1 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
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        long sc = scanner.nextLong() - 1;
        long sc2 = scanner.nextLong();
        long sc3 = scanner.nextLong();
        long sc4 = scanner.nextLong();
        long bet = sc2 - sc + 1;
        
        long tmp = sc2/sc3;
        long tmp2 = sc/sc3;
        long minus1 = tmp - tmp2;

        long tmp3 = sc2/sc4;
        long tmp4 = sc/sc4;
        long minus2 = tmp3 - tmp4;
        
        long tmp5 = sc2/lcm(sc3,sc4);
        long tmp6 = sc/lcm(sc3,sc4);
        long minus3 = tmp5 - tmp6;
        long ans = bet - minus1 - minus2 + minus3;
        System.out.println(ans - 1);
    }
    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);
    }
}