#include <bits/stdc++.h>
using namespace std;
int up_div(int a, int b) { return a / b + (a % b != 0); }
int down_div(int a, int b) { return a / b; }
int main() {
  int a, b;
  cin >> a >> b;
  int res = 0;
  for (int k = 1; k <= a + b; ++k) {
    int d = (a + b) / k;
    int min_k = k;
    int max_k = (a + b) / d;
    res += (up_div(a, d + 1) <= down_div(a, d) &&
            up_div(b, d + 1) <= down_div(b, d)) *
           (min(down_div(a, d) + down_div(b, d), max_k) -
            max(up_div(a, d + 1) + up_div(b, d + 1), min_k) + 1);
    k = max_k;
  }
  cout << res << '\n';
  return 0;
}
