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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	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);
    }
} 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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	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);
    }
} 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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		long lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	} 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 lcm = lcm(c,d); lcm lcm(c,d) lcm c d long aa = (a-1)/d + (a-1)/c - (a-1)/lcm; aa (a-1)/d + (a-1)/c - (a-1)/lcm (a-1)/d + (a-1)/c (a-1)/d (a-1) a 1 d (a-1)/c (a-1) a 1 c (a-1)/lcm (a-1) a 1 lcm long bb = b/d + b/c - b/lcm; bb b/d + b/c - b/lcm b/d + b/c b/d b d b/c b c b/lcm b lcm System.out.println(b - a + 1 - bb + aa) System.out.println System.out System System.out b - a + 1 - bb + aa b - a + 1 - bb b - a + 1 b - a b a 1 bb aa 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 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 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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	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 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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	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);
    }
} 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 lcm = lcm(c,d);
		
		long aa = (a-1)/d + (a-1)/c - (a-1)/lcm;
		long bb = b/d + b/c - b/lcm;
		
		System.out.println(b - a + 1 - bb + aa);
	}
	
	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);
    }
}