#include <bits/stdc++.h>
using namespace std;
long long a, b, c, ans;
signed main() {
  cin >> a >> b;
  c = a + b;
  for (long long i = 1, j; i <= c; i = j + 1) {
    j = (c / (c / i));
    if (a < c / i || b < c / i) continue;
    long long l = (a / (c / i + 1) + (a % (c / i + 1) != 0)), r = a / (c / i);
    long long ll = (b / (c / i + 1) + (b % (c / i + 1) != 0)), rr = b / (c / i);
    if (l <= r && ll <= rr)
      ans += max(0ll, min(j, r + rr) - max(i, l + ll) + 1);
  }
  printf("%lld", ans);
}
