

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	}
	
	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	}
	
	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	} main {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan long b = scan.nextLong(); b scan.nextLong() scan.nextLong scan long c = scan.nextLong(); c scan.nextLong() scan.nextLong scan long d = scan.nextLong(); d scan.nextLong() scan.nextLong scan scan.close() scan.close scan long numC = b/c - (a - 1)/c; numC b/c - (a - 1)/c b/c b c (a - 1)/c (a - 1) a 1 c long numD = b/d - (a - 1)/d; numD b/d - (a - 1)/d b/d b d (a - 1)/d (a - 1) a 1 d long lcmCD = lcm(c, d); lcmCD lcm(c, d) lcm c d long numCD = b/lcmCD - (a - 1)/lcmCD; numCD b/lcmCD - (a - 1)/lcmCD b/lcmCD b lcmCD (a - 1)/lcmCD (a - 1) a 1 lcmCD System.out.println(b - a + 1 - numC - numD + numCD) System.out.println System.out System System.out b - a + 1 - numC - numD + numCD b - a + 1 - numC - numD b - a + 1 - numC - numD b - a + 1 b - a b a 1 numC numD numCD String[] args args public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	} lcm {
		return a * b / gcd(a, b);
	} return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	} gcd {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	} if(a < b) {
			return gcd(b, a);
		} a < b a b {
			return gcd(b, a);
		} return gcd(b, a); gcd(b, a) gcd b a if(b == 0) {
			return a;
		} b == 0 b 0 {
			return a;
		} return a; a return gcd(b, a%b); gcd(b, a%b) gcd b a%b a b long a a long b b public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	}
	
	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	}
	
	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}

} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		scan.close();
		
		long numC = b/c - (a - 1)/c;
		long numD = b/d - (a - 1)/d;
		long lcmCD = lcm(c, d);
		long numCD = b/lcmCD - (a - 1)/lcmCD;
		
		//System.out.println(numC + " " + numD + " " + numCD);
		System.out.println(b - a + 1 - numC - numD + numCD);
		
	}
	
	public static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
	
	public static long gcd(long a, long b) {
		//System.out.println(a + " " + b);
		if(a < b) {
			return gcd(b, a);
		}
		if(b == 0) {
			return a;
		}
		return gcd(b, a%b);
	}

}
