#include <bits/stdc++.h>
using namespace std;
long long inline read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const long long maxn = 100010, mod = 998244353;
long long n, m, s, ans;
signed main() {
  n = read();
  m = read();
  s = n + m;
  for (long long l = 1, r; l <= s; l = r + 1) {
    r = s / (s / l);
    long long k = s / l;
    long long L1 = (n + k) / (k + 1), R1 = n / k;
    long long L2 = (m + k) / (k + 1), R2 = m / k;
    if (L1 <= R1 && L2 <= R2)
      ans += max(min(R1 + R2, r) - max(l, L1 + L2) + 1, 0ll);
  }
  printf("%lld", ans);
  return 0;
}
