#include <bits/stdc++.h>
template <class... Args>
inline __attribute__((always_inline)) void read(Args&... args) {
  (std::cin >> ... >> args);
}
template <class... Args>
inline __attribute__((always_inline)) void write(Args&&... args) {
  (std::cout << ... << std::forward<Args>(args));
}
template <class... Args>
inline __attribute__((always_inline)) void writeln(Args&&... args) {
  write(std::forward<Args>(args)..., '\n');
}
inline __attribute__((always_inline)) void flush_write() {
  std::flush(std::cout);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::fixed(std::cout).precision(20);
  std::cin.exceptions(std::ios_base::failbit);
  std::cin.tie(nullptr);
  int64_t a, b;
  read(a, b);
  int64_t n = a + b;
  int64_t res = 0;
  for (int64_t kl = 1, kr; kl <= n; kl = kr + 1) {
    int64_t tp = n / kl;
    kr = n / tp;
    if (tp > a || tp > b) continue;
    int64_t mn_a = (a + tp) / (tp + 1);
    int64_t mn_b = (b + tp) / (tp + 1);
    int64_t mx_a = a / tp;
    int64_t mx_b = b / tp;
    if (mn_a > mx_a || mn_b > mx_b) continue;
    int64_t mn = mn_a + mn_b;
    int64_t mx = mx_a + mx_b;
    if (mn < kl) mn = kl;
    if (kr < mx) mx = kr;
    res += std::max((int64_t)0, mx - mn + 1);
  }
  writeln(res);
  return 0;
}
