#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, inf = 0x3f3f3f3f;
int a, b;
struct D {
  int l, r;
  bool operator<(const D& b) const { return l != b.l ? l < b.l : r < b.r; }
};
map<int, D> mp, mp2;
vector<D> vec;
int main() {
  scanf("%d%d", &a, &b);
  for (int l = 1, r, k; l <= a; l = r + 1) {
    k = a / l, r = a / k;
    mp[k] = {l, r};
  }
  for (int l = 1, r, k; l <= b; l = r + 1) {
    k = b / l, r = b / k;
    mp2[k] = {l, r};
    if (mp.count(k)) {
      D t = mp[k];
      int L = l + t.l, R = r + t.r;
      vec.push_back({L, R});
    }
  }
  for (int i = 1; i * i <= a; ++i)
    if (a % i == 0) {
      int k = i, x = a / i;
      if (mp2.count(k - 1)) {
        D t = mp2[k - 1];
        int L = x + t.l, R = x + t.r;
        vec.push_back({L, R});
      }
      swap(k, x);
      if (mp2.count(k - 1)) {
        D t = mp2[k - 1];
        int L = x + t.l, R = x + t.r;
        vec.push_back({L, R});
      }
    }
  for (int i = 1; i * i <= b; ++i)
    if (b % i == 0) {
      int k = i, x = b / i;
      if (mp.count(k - 1)) {
        D t = mp[k - 1];
        int L = x + t.l, R = x + t.r;
        vec.push_back({L, R});
      }
      swap(k, x);
      if (mp.count(k - 1)) {
        D t = mp[k - 1];
        int L = x + t.l, R = x + t.r;
        vec.push_back({L, R});
      }
    }
  sort(vec.begin(), vec.end());
  int ans = 0;
  for (int i = 0, la = -1; i < vec.size(); ++i) {
    int l = vec[i].l, r = vec[i].r;
    if (~la) l = max(l, la);
    if (l <= r) ans += r - l + 1;
    la = r + 1;
  }
  printf("%d\n", ans);
  return 0;
}
