#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, i, j, ans, a, b;
int main() {
  cin >> a >> b;
  n = a + b;
  for (i = 1; i <= n; i = j + 1) {
    int t = n / i;
    j = n / t;
    int lb = (b + t) / (t + 1), la = (a + t) / (t + 1);
    int ra = a / t, rb = b / t;
    if (la <= ra && lb <= rb) {
      ans += max(0, min(ra + rb, j) - max(la + lb, i) + 1);
    }
  }
  cout << ans << endl;
  return 0;
}
