import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
} 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() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() - 1; a sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 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 lcm = lcm(c, d); lcm lcm(c, d) lcm c d long e = b - a; e b - a b a long f = a / c; f a / c a c long g = a / d; g a / d a d long h = a / lcm; h a / lcm a lcm long ans1 = a - f - g + h; ans1 a - f - g + h a - f - g a - f - g a f g h long i = b / c; i b / c b c long j = b / d; j b / d b d long k = b / lcm; k b / lcm b lcm long ans2 = b - i - j + k; ans2 b - i - j + k b - i - j b - i - j b i j k long ans = ans2 - ans1; ans ans2 - ans1 ans2 ans1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b final long a a final long b b public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    } gcd {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    } if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        } a < b a b {
            long tmp = a;
            a = b;
            b = tmp;
        } long tmp = a; tmp a a = b a b b = tmp b tmp long r = -1; r -1 1 while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        } r != 0 r 0 {
            r = a % b;
            a = b;
            b = r;
        } r = a % b r a % b a b a = b a b b = r b r return a; a long a a long b b public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong() - 1;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long lcm = lcm(c, d);
        long e = b - a;
        long f = a / c;
        long g = a / d;
        long h = a / lcm;
        long ans1 = a - f - g + h;
        long i = b / c;
        long j = b / d;
        long k = b / lcm;
        long ans2 = b - i - j + k;
        long ans = ans2 - ans1;
        System.out.println(ans);
    }

    public static final long lcm(final long a, final long b) {
        return a * b / gcd(a, b);
    }

    public static final long gcd(long a, long b) {
        if (a < b) {
            long tmp = a;
            a = b;
            b = tmp;
        }
        long r = -1;
        while (r != 0) {
            r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
}