#include <bits/stdc++.h>
using namespace std;
int read() {
  char x = getchar();
  int ans = 0, flag = 1;
  while (!isdigit(x))
    if (x == '-')
      flag = -1, x = getchar();
    else
      x = getchar();
  while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
  return ans * flag;
}
int n, m;
int main() {
  cin >> n >> m;
  long long ans = 0;
  for (int L = 1, R; L <= n + m; L = R + 1) {
    R = (n + m) / ((n + m) / L);
    int tmp = (n + m) / L;
    int l1 = (n + tmp) / (tmp + 1), l2 = (m + tmp) / (tmp + 1);
    int r1 = n / tmp, r2 = m / tmp;
    if (l1 <= r1 && l2 <= r2)
      ans += max(0, min(r1 + r2, R) - max(l1 + l2, L) + 1);
  }
  cout << ans;
  return 0;
}
