#include <bits/stdc++.h>
using namespace std;
namespace Fread {
const int MAXN = 1 << 20;
char buf[MAXN], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, MAXN, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
inline int read() {
  int f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
inline long long readll() {
  long long f = 1, x = 0;
  char ch = Fread::getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = Fread::getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = Fread::getchar();
  }
  return x * f;
}
int main() {
  int a = read(), b = read(), n = a + b;
  long long ans = 0;
  for (int i = 1, j; i <= n; i = j + 1) {
    j = n / (n / i);
    int g = n / i;
    assert(g == n / j);
    int a_min = a / (g + 1) + (a % (g + 1) != 0);
    int a_max = a / g;
    int b_min = b / (g + 1) + (b % (g + 1) != 0);
    int b_max = b / g;
    if (a_min > a_max || b_min > b_max) continue;
    ans += min(j, a_max + b_max) - max(i, a_min + b_min) + 1;
  }
  cout << ans << endl;
  return 0;
}
