#include <bits/stdc++.h>
const int N = 2e5 + 10;
const int mod = 998244353;
using namespace std;
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  int n = a + b, ans = 0;
  for (int l = 1, r; l <= n; l = r + 1) {
    r = n / (n / l);
    int g = n / l;
    if (a < g || b < g) continue;
    int al = (a + g) / (g + 1), ah = a / g, bl = (b + g) / (g + 1), bh = b / g;
    if (al <= ah && bl <= bh)
      ans += max(0, min(r, bh + ah) - max(l, al + bl) + 1);
  }
  printf("%d\n", ans);
  return 0;
}
