#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0' && ch <= '9')) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
char f[20];
int cnt;
inline void pint(int x) {
  cnt = 0;
  if (x == 0) putchar('0');
  while (x) {
    f[++cnt] = x % 10 + '0';
    x /= 10;
  }
  while (cnt) putchar(f[cnt--]);
  putchar('\n');
}
int a, b, qa, qb, ans, n, ls, l1, l2, r1, r2;
signed main() {
  a = read(), b = read();
  n = a + b;
  for (register int l = 1, r; l <= n; l = r + 1) {
    ls = n / l, r = n / ls;
    if (a < ls || b < ls) continue;
    l1 = (a + ls) / (ls + 1), r1 = a / ls;
    l2 = (b + ls) / (ls + 1), r2 = b / ls;
    if (r1 >= l1 && r2 >= l2)
      ans += max(0, min(r1 + r2, r) - max(l1 + l2, l) + 1);
  }
  pint(ans);
  return 0;
}
