#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
  static char c;
  static bool neg;
  x = 0, c = getchar(), neg = false;
  for (; !isdigit(c); c = getchar()) {
    if (c == '-') {
      neg = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (neg) {
    x = -x;
  }
}
int n, m, len;
int main() {
  read(n), read(m);
  len = n + m;
  int ans = 0;
  for (int l = 1, r, g, lN, rN, lM, rM, cur; l <= len; l = r + 1) {
    g = len / l, r = len / g;
    if (g <= n && g <= m) {
      lN = (n + g) / (g + 1), rN = n / g;
      lM = (m + g) / (g + 1), rM = m / g;
      if (rN >= lN && rM >= lM) {
        cur = std::min(rN + rM, r) - std::max(lN + lM, l) + 1;
        if (cur > 0) {
          ans += cur;
        }
      }
    }
  }
  printf("%d\n", ans);
}
