#include <bits/stdc++.h>
using namespace std;
int a, b, ans, tot;
int main() {
  ios::sync_with_stdio(false);
  cin >> a >> b;
  tot = a + b;
  for (int l = 1, r; l <= tot; l = r + 1) {
    r = tot / (tot / l);
    int p = tot / l;
    int L1 = (a + p) / (p + 1), R1 = a / p;
    int L2 = (b + p) / (p + 1), R2 = b / p;
    if (L1 <= R1 && L2 <= R2)
      ans += max(0, min(R1 + R2, r) - max(L1 + L2, l) + 1);
  }
  cout << ans << endl;
  return 0;
}
