import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    }

    private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    }
} 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(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    }

    private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() a sc.nextLong() sc.nextLong sc b = sc.nextLong() b sc.nextLong() sc.nextLong sc c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long x = b/c + b/d - b/lcm(c, d); x b/c + b/d - b/lcm(c, d) b/c + b/d b/c b c b/d b d b/lcm(c, d) b lcm(c, d) lcm c d long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d); y (a-1)/c + (a-1)/d - (a-1)/lcm(c, d) (a-1)/c + (a-1)/d (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/lcm(c, d) (a-1) a 1 lcm(c, d) lcm c d System.out.println((b-a+1)-(x-y)) System.out.println System.out System System.out (b-a+1)-(x-y) (b-a+1) b-a b a 1 (x-y) x y String args[] args private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    } lcm {
        return c * d / gcd(c, d);
    } return c * d / gcd(c, d); c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d long c c long d d private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    } gcd {
        if (b == 0) return a;
        else return gcd(b, a%b);
    } if (b == 0) return a;
        else return gcd(b, a%b); b == 0 b 0 return a; a return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b 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(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    }

    private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    }
} public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    }

    private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long x = b/c + b/d - b/lcm(c, d);
        long y = (a-1)/c + (a-1)/d - (a-1)/lcm(c, d);

        System.out.println((b-a+1)-(x-y));
    }

    private static long lcm(long c, long d) {
        return c * d / gcd(c, d);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        else return gcd(b, a%b);
    }
}
