#include <bits/stdc++.h>
using namespace std;
int N, M, L;
long long Ans;
int main() {
  cin >> N >> M, L = N + M;
  for (int g, l = 1, r; l <= L; l = r + 1) {
    g = L / l, r = L / g;
    if (N < g || M < g) continue;
    int ln = (N + g) / (g + 1), hn = N / g;
    int lm = (M + g) / (g + 1), hm = M / g;
    if (hn >= ln && hm >= lm)
      Ans += max(0ll, 1ll * (min(hn + hm, r) - max(l, lm + ln) + 1));
  }
  cout << Ans << endl;
  return 0;
}
