import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	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.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	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 keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) long A  = keyboard.nextLong(); A keyboard.nextLong() keyboard.nextLong keyboard long B  = keyboard.nextLong(); B keyboard.nextLong() keyboard.nextLong keyboard long C  = keyboard.nextLong(); C keyboard.nextLong() keyboard.nextLong keyboard long D  = keyboard.nextLong(); D keyboard.nextLong() keyboard.nextLong keyboard long b = 0; b 0 long a = 0; a 0 b = B - (B/C +B/D - B/(lcm(C, D))) b B - (B/C +B/D - B/(lcm(C, D))) B (B/C +B/D - B/(lcm(C, D))) B/C +B/D B/C B C B/D B D B/(lcm(C, D)) B (lcm(C, D)) lcm C D a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D))) a (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D))) (A-1) A 1 ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D))) (A-1)/C +(A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/(lcm(C, D)) (A-1) A 1 (lcm(C, D)) lcm C D System.out.println(b - a) System.out.println System.out System System.out b - a b a keyboard.close() keyboard.close keyboard String[] args args 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 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 keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	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 keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	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.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	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);
        }
}
