import java.util.Scanner;

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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return n;
    }
} import java.util.Scanner; Scanner 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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return 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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    } 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 countA = b / c; countA b / c b c long countB = b / d; countB b / d b d long countC = (a - 1) / c; countC (a - 1) / c (a - 1) a 1 c long countD = (a - 1) / d; countD (a - 1) / d (a - 1) a 1 d long cd = lcm(c, d); cd lcm(c, d) lcm c d long countE = b / cd; countE b / cd b cd long countF = (a - 1) / cd; countF (a - 1) / cd (a - 1) a 1 cd long ans = countA + countB - countC - countD - (countE - countF); ans countA + countB - countC - countD - (countE - countF) countD countA + countB - countC - countD - (countE - countF) countA + countB countA countB countC countD (countE - countF) countE countF ans = b - a + 1 - ans ans b - a + 1 - ans b - a + 1 b - a b a 1 ans System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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 private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return n;
    } gcd {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        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 reminder = 0; reminder 0 while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        } (reminder = m % n) != 0 (reminder = m % n) reminder m % n m n 0 {
            m = n;
            n = reminder;
        } m = n m n n = reminder n reminder return n; 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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return 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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return n;
    }
} Main
import java.util.Scanner;

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 countA = b / c;
        long countB = b / d;
        long countC = (a - 1) / c;
        long countD = (a - 1) / d;
        long cd = lcm(c, d);
        long countE = b / cd;
        long countF = (a - 1) / cd;
        
        long ans = countA + countB - countC - countD - (countE - countF);
        ans = b - a + 1 - ans;
        System.out.println(ans);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    
    private static long gcd(long m, long n) {
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long reminder = 0;
        while((reminder = m % n) != 0) {
            m = n;
            n = reminder;
        }
        return n;
    }
}