import java.math.BigInteger;
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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	}
	
    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.math.BigInteger; BigInteger java.math 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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	}
	
    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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	} 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 gcd = c * d / gcd(c , d); gcd c * d / gcd(c , d) c * d c d gcd(c , d) gcd c d long acc = (a - 1) / c; acc (a - 1) / c (a - 1) a 1 c long add = (a - 1)  /d; add (a - 1)  /d (a - 1) a 1 d long acd = (a - 1) / gcd; acd (a - 1) / gcd (a - 1) a 1 gcd long bcc = b / c; bcc b / c b c long bdd = b / d; bdd b / d b d long bcd = b / gcd; bcd b / gcd b gcd long ansa = a - (acc + add - acd); ansa a - (acc + add - acd) a (acc + add - acd) acc + add acc add acd long ansb = b - (bcc + bdd - bcd); ansb b - (bcc + bdd - bcd) b (bcc + bdd - bcd) bcc + bdd bcc bdd bcd System.out.println(ansb - ansa + 1) System.out.println System.out System System.out ansb - ansa + 1 ansb - ansa ansb ansa 1 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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	}
	
    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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	}
	
    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.math.BigInteger;
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 gcd = c * d / gcd(c , d);
		
		long acc = (a - 1) / c;
		long add = (a - 1)  /d;
		long acd = (a - 1) / gcd;
		
		long bcc = b / c;
		long bdd = b / d;
		long bcd = b / gcd;
		
		long ansa = a - (acc + add - acd);
		long ansb = b - (bcc + bdd - bcd);

		
		
		System.out.println(ansb - ansa + 1);
		
		
		
		

		
		
	}
	
    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);
    }
	
}

 