#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
using namespace std;
int main() {
  long long n, a, b;
  scanf("%lld", &a), scanf("%lld", &b), n = a + b;
  long long ans = 0;
  for (long long l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    long long t = n / l, al = (a + t) / (1 + t), ar = a / t,
              bl = (b + t) / (1 + t), br = b / t;
    if (al <= ar && bl <= br)
      ans += max(0ll, min(r, ar + br) - max(l, al + bl) + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
