#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  int n = a + b;
  int l = 1;
  int ans = 0;
  while (l <= n) {
    int g = n / l;
    if (a < g || b < g) {
      l = n / g + 1;
      continue;
    }
    int r = n / g;
    int maxa = (a) / (g);
    int maxb = (b) / (g);
    int mina = (a + g) / (g + 1);
    int minb = (b + g) / (g + 1);
    if (maxa >= mina && maxb >= minb)
      ans += max(0, min(r, maxa + maxb) - max(l, mina + minb) + 1);
    l = r + 1;
  }
  cout << ans << "\n";
}
