#include <bits/stdc++.h>
using namespace std;
int a, b, n, ans;
int main() {
  cin >> a >> b;
  n = a + b;
  for (int i = 1, j = 1; i <= n; i = j + 1) {
    j = n / (n / i);
    int tmp = n / i;
    if (a < tmp || b < tmp) continue;
    int al = a / (tmp + 1) + (a % (tmp + 1) != 0), ar = a / tmp;
    int bl = b / (tmp + 1) + (b % (tmp + 1) != 0), br = b / tmp;
    if (al <= ar && bl <= br)
      ans += max(0, min(j, ar + br) - max(i, al + bl) + 1);
  }
  cout << ans << endl;
}
