import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
} Main public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  } main {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) long st = in.nextLong(); st in.nextLong() in.nextLong in long en = in.nextLong(); en in.nextLong() in.nextLong in long mod1 = in.nextLong(); mod1 in.nextLong() in.nextLong in long mod2 = in.nextLong(); mod2 in.nextLong() in.nextLong in in.close() in.close in long mod1and2 = lcmul(mod1, mod2); mod1and2 lcmul(mod1, mod2) lcmul mod1 mod2 long countand = en / mod1and2; countand en / mod1and2 en mod1and2 countand -= (st - 1) / mod1and2 countand (st - 1) / mod1and2 (st - 1) st 1 mod1and2 long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2; countor en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2 en / mod1 - (st - 1) / mod1 + en / mod2 en / mod1 - (st - 1) / mod1 en / mod1 en mod1 (st - 1) / mod1 (st - 1) st 1 mod1 en / mod2 en mod2 (st - 1) / mod2 (st - 1) st 1 mod2 long ans = en - st - countor + countand  + 1; ans en - st - countor + countand  + 1 en - st - countor + countand  + 1 en - st - countor en - st - countor en st countor countand 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  } gcdiv {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  } while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    } a != b a b {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    } if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      } a > b a b {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } a -= b * (a / b) a b * (a / b) b (a / b) a b if (a == 0) {
          a = b;
        } a == 0 a 0 {
          a = b;
        } a = b a b if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      } b > a b a {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      } b -= a * (b / a) b a * (b / a) a (b / a) b a if (b == 0) {
          b = a;
        } b == 0 b 0 {
          b = a;
        } b = a b a return a; a long a a long b b public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  } lcmul {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  } long gcdiv = gcdiv(a, b); gcdiv gcdiv(a, b) gcdiv a b a /= gcdiv a gcdiv b /= gcdiv b gcdiv return a * b * gcdiv; a * b * gcdiv a * b * gcdiv a b gcdiv long a a long b b public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  } lcmul {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  } a /= gcdiv a gcdiv b /= gcdiv b gcdiv return a * b * gcdiv; a * b * gcdiv a * b * gcdiv a b gcdiv long a a long b b long gcdiv gcdiv public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    long st = in.nextLong();
    long en = in.nextLong();
    long mod1 = in.nextLong();
    long mod2 = in.nextLong();
    in.close();
    long mod1and2 = lcmul(mod1, mod2);
    long countand = en / mod1and2;
    countand -= (st - 1) / mod1and2;
        long countor = en / mod1 - (st - 1) / mod1 + en / mod2 - (st - 1) / mod2;
    long ans = en - st - countor + countand  + 1;
    System.out.println(ans);
  }
  public static long gcdiv(long a, long b) {
    while (a != b) {
      if (a > b) {
        a -= b * (a / b);
        if (a == 0) {
          a = b;
        }
      } else if (b > a) {
        b -= a * (b / a);
        if (b == 0) {
          b = a;
        }
      }
    }
    return a;
  }
  public static long lcmul(long a, long b) {
    long gcdiv = gcdiv(a, b);
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
  public static long lcmul(long a, long b, long gcdiv) {
    a /= gcdiv;
    b /= gcdiv;
    return a * b * gcdiv;
  }
}