#include <bits/stdc++.h>
using namespace std;
int a, b;
void init() {}
void Time_decreasing() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void enter() { scanf("%d %d", &a, &b); }
void solve() {
  int n = a + b;
  int res = 0;
  int left = 1;
  while (left <= n) {
    int g = n / left;
    if (a < g || b < g) {
      left = n / g + 1;
      continue;
    }
    int right = n / g;
    int a_low = (a + g) / (g + 1);
    int a_high = a / g;
    int b_low = (b + g) / (g + 1);
    int b_high = b / g;
    if (a_low <= a_high && b_low <= b_high)
      res = res +
            max(0, min(a_high + b_high, right) - max(a_low + b_low, left) + 1);
    left = right + 1;
  }
  printf("%d", res);
}
int main() {
  init();
  Time_decreasing();
  enter();
  solve();
}
