import 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} import java.util.*; util.* java 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B =sc.nextLong();
        long C =sc.nextLong();
        long D =sc.nextLong();
        long num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    } 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 num1 num1 num2 num2 num3 num3 num4 num4 num5 num5 num6 num6 opt; opt long cd = C*D/gcd(C,D); cd C*D/gcd(C,D) C*D C D gcd(C,D) gcd C D num1 = B/C num1 B/C B C num2 = B/D num2 B/D B D num3 = B/cd num3 B/cd B cd num4 = (A-1)/C num4 (A-1)/C (A-1) A 1 C num5 = (A-1)/D num5 (A-1)/D (A-1) A 1 D num6 = (A-1)/cd num6 (A-1)/cd (A-1) A 1 cd opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6)) opt (B-A+1)-(num1+num2-num3-(num4+num5-num6)) (B-A+1) B-A B A 1 (num1+num2-num3-(num4+num5-num6)) num1+num2-num3-(num4+num5-num6) num1+num2 num1 num2 num3 (num4+num5-num6) num4+num5 num4 num5 num6 System.out.println(opt) System.out.println System.out System System.out opt String [] args args private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
} Main
import 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 num1,num2,num3,num4,num5,num6,opt;
        long cd = C*D/gcd(C,D);
        num1 = B/C;
        num2 = B/D;
        num3 = B/cd;
        num4 = (A-1)/C;
        num5 = (A-1)/D;
        num6 = (A-1)/cd;
        opt = (B-A+1)-(num1+num2-num3-(num4+num5-num6));
        System.out.println(opt);
    }
    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
}
