#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a > b) swap(a, b);
  vector<int> v;
  for (int k = 1; k <= min(a, 35000); k++) {
    v.push_back(a / k);
    if (a % k == 0 && a > k) v.push_back(a / k - 1);
  }
  for (int k = 1; k <= min(35000, a); k++) v.push_back(k);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  int ans = 0;
  for (auto k : v) {
    if (a / k < (a + k) / (k + 1) || b / k < (b + k) / (k + 1)) continue;
    int r = a / k + b / k, l = (a + k) / (k + 1) + (b + k) / (k + 1);
    ans += max(0, r - l + 1);
    if (a % (k + 1) == 0 && b % (k + 1) == 0) ans--;
  }
  cout << ans << endl;
  return 0;
}
