#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 1e7 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ = 225;
const long double EPS = 1e-7;
int a, b;
bool check(int mx1, int mx2, int k) { return (mx1 && mx2 && (mx1 + mx2) >= k); }
int solve(int a, int b) {
  int n = a + b;
  int res = 0;
  for (int l = 1, r, k; l <= n;) {
    k = n / l;
    r = n / k;
    int al = (a + k) / (k + 1);
    int ar = a / k;
    int bl = (b + k) / (k + 1);
    int br = b / k;
    if (al <= ar && bl <= br)
      res += max(0, min(r, ar + br) - max(l, al + bl) + 1);
    l = r + 1;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> b;
  int ans = 0;
  for (int l = 1, r; l <= (a + b); l = r + 1) {
    int x = (a + b) / l;
    r = (a + b) / x;
    int mx1 = a / x;
    int mn1 = (a + x) / (x + 1);
    int mx2 = b / x;
    int mn2 = (b + x) / (x + 1);
    if (mn1 <= mx1 && mn2 <= mx2)
      ans += max(0, min(r, mx1 + mx2) - max(l, mn1 + mn2) + 1);
  }
  cout << ans << '\n';
  return 0;
}
