import java.util.Scanner;

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