#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int n = a + b;
  int res = 0;
  for (int l = 1, r, k; l <= n;) {
    k = n / l;
    r = n / k;
    int al = (a + k) / (k + 1);
    int ar = a / k;
    int bl = (b + k) / (k + 1);
    int br = b / k;
    if (al <= ar && bl <= br)
      res += max(0, min(r, ar + br) - max(l, al + bl) + 1);
    l = r + 1;
  }
  cout << res << endl;
  return 0;
}
