
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	}
	
	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }

    static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    }

    static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    }
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	}
	
	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }

    static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    }

    static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    }
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	} 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 int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long divByC = b/c - (a - 1)/c; divByC b/c - (a - 1)/c b/c b c (a - 1)/c (a - 1) a 1 c long divByD = b/d - (a - 1)/d; divByD 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 divByLCM = b/lcmCD - (a - 1)/lcmCD; divByLCM b/lcmCD - (a - 1)/lcmCD b/lcmCD b lcmCD (a - 1)/lcmCD (a - 1) a 1 lcmCD System.out.println((b - a + 1) - (divByC + divByD - divByLCM)) System.out.println System.out System System.out (b - a + 1) - (divByC + divByD - divByLCM) (b - a + 1) b - a b a 1 (divByC + divByD - divByLCM) divByC + divByD divByC divByD divByLCM String[] args args static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    } gcd {
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    } int tmp; tmp while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	} a % b != 0 a % b a b 0 {
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	} tmp = b tmp b b = a % b b a % b a b a = tmp a tmp return b; b int a a int b b static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    } lcm {
    	return (long)a*(b/gcd);
    } return (long)a*(b/gcd); (long)a*(b/gcd) (long)a (b/gcd) b gcd int a a int b b int gcd gcd static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    } lcm {
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    } int g = gcd(a, b); g gcd(a, b) gcd a b return lcm(a,b,g); lcm(a,b,g) lcm a b g int a a int b b public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	}
	
	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }

    static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    }

    static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    }
} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	}
	
	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }

    static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    }

    static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    }
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		long divByC = b/c - (a - 1)/c;
		long divByD = b/d - (a - 1)/d;
		
//		System.out.println("divByC "+divByC);
//		System.out.println("divByD "+divByD);
		long lcmCD = lcm(c, d);
		
		long divByLCM = b/lcmCD - (a - 1)/lcmCD;
		
		System.out.println((b - a + 1) - (divByC + divByD - divByLCM));
	}
	
	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }

    static long lcm(int a, int b, int gcd){
    	return (long)a*(b/gcd);
    }

    static long lcm(int a, int b){
    	int g = gcd(a, b);

    	return lcm(a,b,g);
    }
}
