import java.util.Scanner;

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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	}
	public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 }
}
 import java.util.Scanner; Scanner 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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	}
	public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 }
} 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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	} 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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	} 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 = c * d / gcd(c , d); lcm c * d / gcd(c , d) c * d c d gcd(c , d) gcd c d long u = b - a + 1; u b - a + 1 b - a b a 1 long cs = b / c - (a - 1) / c; cs b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long ds = b / d - (a - 1) / d; ds b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long lcms = b / lcm - (a - 1) / lcm; lcms b / lcm - (a - 1) / lcm b / lcm b lcm (a - 1) / lcm (a - 1) a 1 lcm sc.close() sc.close sc System.out.println(u - cs - ds + lcms) System.out.println System.out System System.out u - cs - ds + lcms u - cs - ds u - cs - ds u cs ds lcms String[] args args public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 } gcd {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 } if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 ); num2 == 0 num2 0 return num1; num1 return gcd(num2 , num1 % num2 ); gcd(num2 , num1 % num2 ) gcd num2 num1 % num2 num1 num2 long num1 num1 long num2 num2 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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	}
	public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 }
} 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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	}
	public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 }
} Main
import java.util.Scanner;

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 = c * d / gcd(c , d);

		long u = b - a + 1;
		long cs = b / c - (a - 1) / c;
		long ds = b / d - (a - 1) / d;
		long lcms = b / lcm - (a - 1) / lcm;
		sc.close();
		System.out.println(u - cs - ds + lcms);

	}
	public static long gcd(long num1,long num2) {
        if(num2 == 0) return num1;
        else return gcd(num2 , num1 % num2 );
 }
}

