import java.util.*;
import java.lang.*;

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 count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    }


 //最大公約数を出すメソッド
    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);
    }
} import java.util.*; util.* java import java.lang.*; lang.* java 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 count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    }


 //最大公約数を出すメソッド
    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);
    }
} 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 count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    } 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 count = 0; count 0 long ansc = 0; ansc 0 long ansd = 0; ansd 0 long anscd = 0; anscd 0 long ans = 0; ans 0 if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        } a % c != 0 a % c a c 0 {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ansc ((((b / c)) * c     -       ((a / c) + 1) * c) / c) (((b / c)) * c     -       ((a / c) + 1) * c) ((b / c)) * c ((b / c)) b c c ((a / c) + 1) * c ((a / c) + 1) (a / c) a c 1 c c {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        } ansc = ((((b / c)) * c - ((a / c) * c)) / c) ansc ((((b / c)) * c - ((a / c) * c)) / c) (((b / c)) * c - ((a / c) * c)) ((b / c)) * c ((b / c)) b c c ((a / c) * c) (a / c) a c c c if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        } a % d != 0 a % d a d 0 {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d ansd ((b / d) * d -   (((a / d) + 1)* d))   / d ((b / d) * d -   (((a / d) + 1)* d)) (b / d) * d (b / d) b d d (((a / d) + 1)* d) ((a / d) + 1) (a / d) a d 1 d d {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        } ansd = (((b / d)) * d - (a / d)  * d) / d ansd (((b / d)) * d - (a / d)  * d) / d (((b / d)) * d - (a / d)  * d) ((b / d)) * d ((b / d)) b d d (a / d)  * d (a / d) a d d d long lcm = c * d / gcd(c, d); lcm c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        } a % lcm !=0 a % lcm a lcm 0 {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        } anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1 anscd ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1 ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm)) (((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) ((b / (lcm)) * (lcm)) (b / (lcm)) b (lcm) (lcm) (((a / (lcm)) + 1) * (lcm)) ((a / (lcm)) + 1) (a / (lcm)) a (lcm) 1 (lcm) (lcm) 1 {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        } anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1 anscd ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1 ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm)) (((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) ((b / (lcm)) * (lcm)) (b / (lcm)) b (lcm) (lcm) (((a / (lcm))) * (lcm)) ((a / (lcm))) a (lcm) (lcm) (lcm) 1 ans = b - a + 1 - ansc - ansd + anscd ans b - a + 1 - ansc - ansd + anscd b - a + 1 - ansc - ansd b - a + 1 - ansc - ansd b - a + 1 b - a b a 1 ansc ansd anscd System.out.println(ans) System.out.println System.out System System.out ans 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
import java.util.*;
import java.lang.*;

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 count = 0;
        long ansc = 0;
        long ansd = 0;
        long anscd = 0;
        long ans = 0;
        if (a % c != 0) {
            ansc = ((((b / c)) * c     -       ((a / c) + 1) * c) / c) ;
        } else {
            ansc = ((((b / c)) * c - ((a / c) * c)) / c) ;
        }
        if (a % d != 0) {
            ansd = ((b / d) * d -   (((a / d) + 1)* d))   / d;
        } else {
            ansd = (((b / d)) * d - (a / d)  * d) / d ;
        }

//２つの値の最小公倍数
        long lcm = c * d / gcd(c, d);
        if (a % lcm !=0) {
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm)) + 1) * (lcm))) / (lcm))-1;
        }else{
            anscd = ((((b / (lcm)) * (lcm)) - (((a / (lcm))) * (lcm))) / (lcm))-1;
        }
        ans = b - a + 1 - ansc - ansd + anscd;
        System.out.println(ans);
//        for(long i= a; i<=b; i++){
//            if(i%c !=0 && i% d !=0){
//                count++;
//            }
//        }
    }


 //最大公約数を出すメソッド
    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);
    }
}
