#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  int n = a + b;
  int ans = 0;
  for (int l = 1, r = 0; l <= n; l = r + 1) {
    int g = n / l;
    r = n / g;
    if (a < g || b < g) {
      continue;
    }
    int al = (a + g) / (g + 1);
    int ar = a / g;
    int bl = (b + g) / (g + 1);
    int br = b / g;
    if (al <= ar && bl <= br)
      ans += max(0, min(r, ar + br) - max(l, al + bl) + 1);
  }
  printf("%d\n", ans);
  return 0;
}
