#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 1;
long long A, B;
long long ans;
vector<pair<long long, long long> > vt;
void calc(long long x) {
  long long sa, ea, sb, eb, s, e;
  ea = A / x;
  if (ea == 0) return;
  if (A / ea != x) {
    if (A % (x + 1LL) != 0) return;
    sa = eb = A / (x + 1LL);
  } else {
    sa = A / (x + 1LL) + 1LL;
  }
  eb = B / x;
  if (eb == 0) return;
  if (B / eb != x) {
    if (B % (x + 1LL) != 0) return;
    sb = eb = B / (x + 1LL);
  } else {
    sb = B / (x + 1LL) + 1LL;
  }
  if (A / ea != x && B / eb != x) return;
  if (A / ea != x || B / eb != x) {
    vt.push_back({sa + sb, ea + eb});
    return;
  }
  s = sa + sb;
  e = ea + eb;
  if (A % (x + 1LL) == 0 || B % (x + 1LL) == 0) {
    s--;
  }
  vt.push_back({s, e});
}
int main() {
  cin >> A >> B;
  long long sa = 1, ea = 1, q;
  while (sa <= A) {
    q = A / sa;
    ea = A / q;
    if (q != 1) calc(q - 1);
    calc(q);
    sa = ea + 1;
  }
  sort(vt.begin(), vt.end());
  long long mx = 0;
  for (int i = 0; i < vt.size(); i++) {
    if (vt[i].second <= mx) continue;
    vt[i].first = max(mx + 1, vt[i].first);
    ans += vt[i].second - vt[i].first + 1;
    mx = vt[i].second;
  }
  cout << ans;
  return 0;
}
