#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, n;
  scanf("%d%d", &a, &b), n = a + b;
  long long ans = 0;
  for (int l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    int t = n / l;
    if (a / t < (a + t) / (t + 1) || b / t < (b + t) / (t + 1)) continue;
    ans += max(0, min(r, a / t + b / t) -
                      max(l, (a + t) / (t + 1) + (b + t) / (t + 1)) + 1);
  }
  printf("%lld\n", ans);
  return 0;
}
