#include <bits/stdc++.h>
int main() {
  long long a, b;
  scanf("%lld%lld", &a, &b);
  long long n = a + b;
  long long ans = 0;
  for (long long l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    long long g = n / l;
    long long la = (a + g) / (g + 1), ra = a / g;
    long long lb = (b + g) / (g + 1), rb = b / g;
    if (la > ra) continue;
    if (lb > rb) continue;
    long long ll = std::max(l, la + lb), rr = std::min(r, ra + rb);
    if (ll > rr) continue;
    ans += rr - ll + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
