#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
const int maxn = 1e5 + 10;
int a, b, n, ans;
int main() {
  read(a), read(b);
  n = a + b;
  for (register int i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i);
    int t = n / i;
    if (a < t || b < t) continue;
    int al = a / (t + 1) + (a % (t + 1) != 0), ar = a / t;
    int bl = b / (t + 1) + (b % (t + 1) != 0), br = b / t;
    if (al <= ar && bl <= br) ans += min(j, ar + br) - max(i, al + bl) + 1;
  }
  printf("%d\n", ans);
}
