import java.util.*;

public class Main{
    public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    }
} import java.util.*; util.* java public class Main{
    public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    }
} Main public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    } gcd {
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    } if(m < n){
            return gcd(m,n);
        } m < n m n {
            return gcd(m,n);
        } return gcd(m,n); gcd(m,n) gcd m n if(n==0){
            return m;
        } n==0 n 0 {
            return m;
        } return m; m return gcd(n, m%n); gcd(n, m%n) gcd n m%n m n long n n long m m public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    } main {
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long A = scanner.nextLong(); A scanner.nextLong() scanner.nextLong scanner long B = scanner.nextLong(); B scanner.nextLong() scanner.nextLong scanner long C = scanner.nextLong(); C scanner.nextLong() scanner.nextLong scanner long D = scanner.nextLong(); D scanner.nextLong() scanner.nextLong scanner long lcmCD = C * D / gcd(C,D); lcmCD C * D / gcd(C,D) C * D C D gcd(C,D) gcd C D long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C); divC Math.floorDiv(B, C) - Math.floorDiv(A-1, C) Math.floorDiv(B, C) Math.floorDiv Math B C Math.floorDiv(A-1, C) Math.floorDiv Math A-1 A 1 C long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D); divD Math.floorDiv(B, D) - Math.floorDiv(A-1, D) Math.floorDiv(B, D) Math.floorDiv Math B D Math.floorDiv(A-1, D) Math.floorDiv Math A-1 A 1 D long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD); divCD Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD) Math.floorDiv(B, lcmCD) Math.floorDiv Math B lcmCD Math.floorDiv(A-1, lcmCD) Math.floorDiv Math A-1 A 1 lcmCD long undiv = B - A + 1 - divC - divD + divCD; undiv B - A + 1 - divC - divD + divCD B - A + 1 - divC - divD B - A + 1 - divC - divD B - A + 1 B - A B A 1 divC divD divCD System.out.println(undiv) System.out.println System.out System System.out undiv String args[] args public class Main{
    public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    }
} public class Main{
    public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    }
} Main
import java.util.*;

public class Main{
    public static long gcd(long n, long m){
        if(m < n){
            return gcd(m,n);
        }
        if(n==0){
            return m;
        }
        return gcd(n, m%n);
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long A = scanner.nextLong();
        long B = scanner.nextLong();
        long C = scanner.nextLong();
        long D = scanner.nextLong();

        long lcmCD = C * D / gcd(C,D);

        long divC = Math.floorDiv(B, C) - Math.floorDiv(A-1, C);
        long divD = Math.floorDiv(B, D) - Math.floorDiv(A-1, D);
        long divCD = Math.floorDiv(B, lcmCD) - Math.floorDiv(A-1, lcmCD);
        long undiv = B - A + 1 - divC - divD + divCD;

        System.out.println(undiv);
    }
}