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