import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 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.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 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 sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	} main {
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Long A = sc.nextLong() - 1; A sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 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 CDkaburi = lcm(C,D); CDkaburi lcm(C,D) lcm C D Long AC = A / C; AC A / C A C Long AD = A / D; AD A / D A D Long ACD = A / CDkaburi; ACD A / CDkaburi A CDkaburi Long Awarenai = A - (AC + AD) + ACD; Awarenai A - (AC + AD) + ACD A - (AC + AD) A (AC + AD) AC AD ACD Long BC = B / C; BC B / C B C Long BD = B / D; BD B / D B D Long BCD = B / CDkaburi; BCD B / CDkaburi B CDkaburi Long Bwarenai = B - (BC + BD) + BCD; Bwarenai B - (BC + BD) + BCD B - (BC + BD) B (BC + BD) BC BD BCD System.out.println(Bwarenai - Awarenai) System.out.println System.out System System.out Bwarenai - Awarenai Bwarenai Awarenai 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 sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 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 sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 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.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 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);
}
}
