#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
int main() {
  int a, b;
  read(a);
  read(b);
  int n = a + b, ans = 0;
  int l = 1;
  while (l <= n) {
    int g = n / l;
    if (a < g || b < g) {
      l = n / g + 1;
      continue;
    }
    int r = n / g;
    int al = (a + g) / (g + 1), ar = a / g;
    int bl = (b + g) / (g + 1), br = b / g;
    if (al <= ar && bl <= br)
      ans += max(0, min(r, ar + br) - max(l, al + bl) + 1);
    l = r + 1;
  }
  printf("%d\n", ans);
  return 0;
}
