#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  long long a, b;
  cin >> a >> b;
  long long n = a + b, sol = 0;
  for (long long k = 1; k < n; k = n / (n / (k + 1))) {
    long long plo = n / (k + 1) + 1;
    long long phi = n / k;
    long long xlo = (a + k) / (k + 1), xhi = a / k;
    long long ylo = (b + k) / (k + 1), yhi = b / k;
    long long lo = max(xlo + ylo, plo);
    long long hi = min(xhi + yhi, phi);
    if (lo <= hi && xlo <= xhi && ylo <= yhi) sol += hi - lo + 1;
  }
  cout << sol << '\n';
}
