#include <bits/stdc++.h>
template <typename T>
inline T max(T a, T b) {
  return a > b ? a : b;
}
template <typename T>
inline T min(T a, T b) {
  return a < b ? a : b;
}
template <typename T>
inline bool cmax(T &a, T b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool cmin(T &a, T b) {
  return a > b ? a = b, 1 : 0;
}
int main() {
  long long a, b, ans = 0;
  scanf("%lld%lld", &a, &b);
  for (long long cl = 1, cr, n = a + b; cl <= n; cl = cr + 1) {
    cr = n / (n / cl);
    long long m = n / cl, pp = (a + m) / (m + 1) + (b + m) / (m + 1);
    long long qq = a / m + b / m;
    cmax(pp, cl);
    cmin(qq, cr);
    if (pp <= qq && (a + m) / (m + 1) <= a / m && (b + m) / (m + 1) <= b / m) {
      ans += qq - pp + 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
