#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
multiset<pii> stt;
int a, b;
int main() {
  cin >> a >> b;
  int s = a + b;
  int st = 1;
  int cnt = 0;
  int ans = 0;
  for (; st <= s; st++) {
    cnt++;
    int ed = s / (s / st);
    int k = s / st;
    int r1 = a / k;
    int l1 = (a + k) / (k + 1);
    int r2 = b / k;
    int l2 = (b + k) / (k + 1);
    if (l1 > r1 || l2 > r2) {
      st = ed;
      continue;
    }
    if (l1 + l2 <= ed) {
      ans += min(ed, r1 + r2) - max(st, l1 + l2) + 1;
    }
    st = ed;
  }
  cout << ans << endl;
}
