import java.util.*;

public class Main {
	
	
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	}
		


} import java.util.*; util.* java public class Main {
	
	
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	}
		


} Main 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 private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	} lcm {
	    return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	} 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 long c = sc.nextInt() c sc.nextInt() sc.nextInt sc d=sc.nextInt(); d sc.nextInt() sc.nextInt sc long l = lcm(c,d); l lcm(c,d) lcm c d a-- a long ans1 = a-a/c-a/d+a/l; ans1 a-a/c-a/d+a/l a-a/c-a/d a-a/c-a/d a a/c a c a/d a d a/l a l long ans2 = b-b/c-b/d+b/l; ans2 b-b/c-b/d+b/l b-b/c-b/d b-b/c-b/d b b/c b c b/d b d b/l b l 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 class Main {
	
	
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	}
		


} public class Main {
	
	
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	}
		


} Main
import java.util.*;

public class Main {
	
	
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
	
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong(),b=sc.nextLong();
		long c = sc.nextInt(),d=sc.nextInt();
		
		long l = lcm(c,d);
		a--;
		long ans1 = a-a/c-a/d+a/l;
		long ans2 = b-b/c-b/d+b/l;
		
		long ans = ans2-ans1;
		
		System.out.println(ans);
		
		
		
	}
		


}
