import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   }
   
   static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
} import java.util.*; util.* java public class Main {
    static final int MOD = 1000000007;
	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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   }
   
   static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
} Main static final int MOD = 1000000007; MOD 1000000007 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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   } main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   } 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 x = c / gcd(c, d) * d; x c / gcd(c, d) * d c / gcd(c, d) c gcd(c, d) gcd c d d long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x; aCount (a - 1) / c + (a - 1) / d - (a - 1) / x (a - 1) / c + (a - 1) / d (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / x (a - 1) a 1 x long bCount = b / c + b / d - b / x; bCount b / c + b / d - b / x b / c + b / d b / c b c b / d b d b / x b x System.out.println(b - a + 1 - (bCount - aCount)) System.out.println System.out System System.out b - a + 1 - (bCount - aCount) b - a + 1 b - a b a 1 (bCount - aCount) bCount aCount String[] args args static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   } gcd {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   } if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       } x % y == 0 x % y x y 0 {
           return y;
       } return y; y {
           return gcd(y, x % y);
       } return gcd(y, x % y); gcd(y, x % y) gcd y x % y x y long x x long y y public class Main {
    static final int MOD = 1000000007;
	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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   }
   
   static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
} public class Main {
    static final int MOD = 1000000007;
	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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   }
   
   static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
} Main
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	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 x = c / gcd(c, d) * d;
		long aCount = (a - 1) / c + (a - 1) / d - (a - 1) / x;
		long bCount = b / c + b / d - b / x;
		System.out.println(b - a + 1 - (bCount - aCount));
   }
   
   static long gcd(long x, long y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
}
