#include <bits/stdc++.h>
using namespace std;
int a, b, n, ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  n = a + b;
  for (int i = n, l = 1; i; i = n / (l + 1)) {
    l = n / i;
    if (a / l < (a + l) / (l + 1) || b / l < (b + l) / (l + 1)) continue;
    int sum =
        a / l + b / l -
        max((a + b) / (l + 1) + 1, (a + l) / (l + 1) + (b + l) / (l + 1)) + 1;
    if (sum > 0) ans += sum;
  }
  cout << ans << '\n';
  return 0;
}
