#include <bits/stdc++.h>
using namespace std;
bool home = 1;
signed realMain();
signed main() {
  home = 0;
  if (home) {
    freopen("input", "r", stdin);
  } else {
    ios::sync_with_stdio(0);
    cin.tie(0);
  }
  realMain();
}
long long a, b, n, ret = 0, k1 = 1;
signed realMain() {
  cin >> a >> b;
  n = a + b;
  while (k1 <= n) {
    long long g = n / k1;
    long long k2 = n / g;
    long long f1 = (a + g) / (g + 1), s1 = a / g;
    long long f2 = (b + g) / (g + 1), s2 = b / g;
    if (f1 <= s1 && f2 <= s2) {
      long long kmin = f1 + f2, kmax = s1 + s2;
      kmin = max(kmin, k1);
      kmax = min(kmax, k2);
      if (kmin <= kmax) {
        ret += kmax - kmin + 1;
      }
    }
    k1 = k2 + 1;
  }
  cout << ret << "\n";
  return 0;
}
