import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    }

    private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    }

    private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    }

    private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    }
} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    }

    private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    }

    private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    }

    private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    }
} Main public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    } main {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) BigInteger A = scanner.nextBigInteger(); A scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger B = scanner.nextBigInteger(); B scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger C = scanner.nextBigInteger(); C scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger D = scanner.nextBigInteger(); D scanner.nextBigInteger() scanner.nextBigInteger scanner BigInteger countC = countDivNum(A, B, C); countC countDivNum(A, B, C) countDivNum A B C BigInteger countD = countDivNum(A, B, D); countD countDivNum(A, B, D) countDivNum A B D BigInteger countCD = countDivNum(A, B, lcm(C, D)); countCD countDivNum(A, B, lcm(C, D)) countDivNum A B lcm(C, D) lcm C D BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1)); rangeNum B.subtract(A).add(BigInteger.valueOf(1)) B.subtract(A).add B.subtract(A) B.subtract B A BigInteger.valueOf(1) BigInteger.valueOf BigInteger 1 BigInteger divideNum = countC.add(countD).subtract(countCD); divideNum countC.add(countD).subtract(countCD) countC.add(countD).subtract countC.add(countD) countC.add countC countD countCD System.out.println(rangeNum.subtract(divideNum)) System.out.println System.out System System.out rangeNum.subtract(divideNum) rangeNum.subtract rangeNum divideNum String[] args args private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    } countDivNum {


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    } BigInteger minValue = A; minValue A BigInteger[] valMin = minValue.divideAndRemainder(Divide); valMin minValue.divideAndRemainder(Divide) minValue.divideAndRemainder minValue Divide BigInteger minRemainder = valMin[1]; minRemainder valMin[1] valMin 1 if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        } !minRemainder.equals(BigInteger.valueOf(0)) minRemainder.equals(BigInteger.valueOf(0)) minRemainder.equals minRemainder BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 {
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        } BigInteger diff = Divide.subtract(minRemainder); diff Divide.subtract(minRemainder) Divide.subtract Divide minRemainder minValue = minValue.add(diff) minValue minValue.add(diff) minValue.add minValue diff BigInteger maxValue= B; maxValue B BigInteger[] valMax = maxValue.divideAndRemainder(Divide); valMax maxValue.divideAndRemainder(Divide) maxValue.divideAndRemainder maxValue Divide BigInteger maxRemainder = valMax[1]; maxRemainder valMax[1] valMax 1 if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        } !minRemainder.equals(BigInteger.valueOf(0)) minRemainder.equals(BigInteger.valueOf(0)) minRemainder.equals minRemainder BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 {
            maxValue = maxValue.subtract(maxRemainder);
        } maxValue = maxValue.subtract(maxRemainder) maxValue maxValue.subtract(maxRemainder) maxValue.subtract maxValue maxRemainder if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        } maxValue.compareTo(minValue) == -1 maxValue.compareTo(minValue) maxValue.compareTo maxValue minValue -1 1 {
            return BigInteger.valueOf(0);
        } return BigInteger.valueOf(0); BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        } BigInteger range = maxValue.subtract(minValue); range maxValue.subtract(minValue) maxValue.subtract maxValue minValue BigInteger countRqw = range.divide(Divide); countRqw range.divide(Divide) range.divide range Divide BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1)); countDivNum countRqw.add(BigInteger.valueOf(1)) countRqw.add countRqw BigInteger.valueOf(1) BigInteger.valueOf BigInteger 1 return countDivNum; countDivNum BigInteger A A BigInteger B B BigInteger Divide Divide private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    } gcb {

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    } if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        } A.compareTo(B) == -1 A.compareTo(B) A.compareTo A B -1 1 {
            BigInteger C = A;
            A = B;
            B = C;
        } BigInteger C = A; C A A = B A B B = C B C BigInteger[] valFirst = A.divideAndRemainder(B); valFirst A.divideAndRemainder(B) A.divideAndRemainder A B if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        } valFirst[1] == BigInteger.valueOf(0) valFirst[1] valFirst 1 BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 {
            return B;
        } return B; B while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        } true {
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        } BigInteger[] val = A.divideAndRemainder(B); val A.divideAndRemainder(B) A.divideAndRemainder A B if(val[1] == BigInteger.valueOf(0)){
                break;
            } val[1] == BigInteger.valueOf(0) val[1] val 1 BigInteger.valueOf(0) BigInteger.valueOf BigInteger 0 {
                break;
            } break; BigInteger tmp = B; tmp B B = val[1] B val[1] val 1 A = tmp A tmp BigInteger gcb = B; gcb B return gcb; gcb BigInteger A A BigInteger B B private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    } lcm {
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    } BigInteger lcm = A.multiply(B.divide(gcb(A, B))); lcm A.multiply(B.divide(gcb(A, B))) A.multiply A B.divide(gcb(A, B)) B.divide B gcb(A, B) gcb A B return lcm; lcm BigInteger A A BigInteger B B public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    }

    private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    }

    private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    }

    private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    }
} public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    }

    private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    }

    private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    }

    private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    }
} Main
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        BigInteger A = scanner.nextBigInteger();
        BigInteger B = scanner.nextBigInteger();
        BigInteger C = scanner.nextBigInteger();
        BigInteger D = scanner.nextBigInteger();

        BigInteger countC = countDivNum(A, B, C);
        BigInteger countD = countDivNum(A, B, D);
        BigInteger countCD = countDivNum(A, B, lcm(C, D));

        BigInteger rangeNum = B.subtract(A).add(BigInteger.valueOf(1));
        BigInteger divideNum = countC.add(countD).subtract(countCD);

        System.out.println(rangeNum.subtract(divideNum));

    }

    private static BigInteger countDivNum(BigInteger A, BigInteger B, BigInteger Divide){


        BigInteger minValue = A;
        BigInteger[] valMin = minValue.divideAndRemainder(Divide);
        BigInteger minRemainder = valMin[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            BigInteger diff = Divide.subtract(minRemainder);
            minValue = minValue.add(diff);
        }

        BigInteger maxValue= B;
        BigInteger[] valMax = maxValue.divideAndRemainder(Divide);
        BigInteger maxRemainder = valMax[1];
        if(!minRemainder.equals(BigInteger.valueOf(0))){
            maxValue = maxValue.subtract(maxRemainder);
        }

        if(maxValue.compareTo(minValue) == -1){
            return BigInteger.valueOf(0);
        }else {
            BigInteger range = maxValue.subtract(minValue);
            BigInteger countRqw = range.divide(Divide);

            BigInteger countDivNum = countRqw.add(BigInteger.valueOf(1));

            return countDivNum;
        }
    }

    private static BigInteger gcb(BigInteger A, BigInteger B){

        if(A.compareTo(B) == -1){
            BigInteger C = A;
            A = B;
            B = C;
        }

        BigInteger[] valFirst = A.divideAndRemainder(B);
        if(valFirst[1] == BigInteger.valueOf(0)){
            return B;
        }

        while(true){
            BigInteger[] val = A.divideAndRemainder(B);

            if(val[1] == BigInteger.valueOf(0)){
                break;
            }

            BigInteger tmp = B;
            B = val[1];
            A = tmp;
        }

        BigInteger gcb = B;

        return gcb;
    }

    private static BigInteger lcm(BigInteger A, BigInteger B){
        BigInteger lcm = A.multiply(B.divide(gcb(A, B)));
        return lcm;
    }
}
