#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int n, a, b;
int main() {
  cin >> a >> b;
  n = a + b;
  int ans = 0;
  for (int l = 2, r; l <= n; l = r + 1) {
    int k = n / l;
    r = n / k;
    int x = a / k, y = a % k;
    int f = b / k, g = b % k;
    if (x < y || f < g) continue;
    int p = (x - y) / (1 + k), q = (f - g) / (1 + k);
    int L = x - p + f - q, R = x + f;
    if (x - p == y + p * k && f - q == g + q * k) L++;
    L = max(L, l);
    R = min(R, r);
    if (L <= R) ans += R - L + 1;
  }
  cout << ans << endl;
  return 0;
}
