#include <bits/stdc++.h>
using namespace std;
long long divup(const long long& a, const long long& b) {
  return (a + b - 1) / b;
}
long long solve_for_g(long long a, long long b, long long g, long long l,
                      long long r) {
  long long lowa = divup(a, g + 1), higha = a / g, lowb = divup(b, g + 1),
            highb = b / g;
  if (lowa > higha || lowb > highb) return 0;
  return min(r, higha + highb) - max(l, lowa + lowb) + 1ll;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  set<long long, greater<long long> > s;
  for (long long g = 1; (g - 1) * (g - 1) < a + b; g++) s.insert(g);
  for (long long p = 1; (p - 1) * (p - 1) < a + b; p++) s.insert((a + b) / p);
  long long ans = 0, prev = 1;
  for (long long i : s) {
    ans += solve_for_g(a, b, i, prev, (a + b) / i);
    prev = (a + b) / i + 1;
  }
  cout << ans << "\n";
  return 0;
}
