#include <bits/stdc++.h>
using namespace std;
long long a, b, n;
void solve() {
  cin >> a >> b;
  n = a + b;
  long long ans = 0;
  long long rpre = -42;
  for (long long i = 1; n / i > 0 && a > 0 && b > 0;
       i += (n % i) / (n / i) + 1) {
    long long p = n / i;
    long long c = 0;
    long long xr = (a) / p;
    long long xl = (a + p) / (p + 1);
    long long wr = (b) / p;
    long long wl = (b + p) / (p + 1);
    if (wr >= wl && xr >= xl) {
      long long l = wl + xl;
      long long r = xr + wr;
      c = r - l;
      if (l != rpre) c++;
      ans += c;
      rpre = r;
    }
  }
  cout << (ans) << endl;
}
int main() {
  string problem_name = "";
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
}
