#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  int ans = 0;
  int l = 1;
  int n = a + b;
  while (l <= n) {
    int g = n / l;
    int r = n / g;
    int alow, blow, ahigh, bhigh;
    if (a < g || b < g) goto nxt;
    alow = (a + g) / (g + 1);
    blow = (b + g) / (g + 1);
    ahigh = a / g;
    bhigh = b / g;
    if (alow <= ahigh && blow <= bhigh) {
      ans += max(0, (min(r, ahigh + bhigh) - max(l, alow + blow) + 1));
    }
  nxt:
    l = r + 1;
  }
  cout << ans << endl;
  return 0;
}
