#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, t, la, lb, ha, hb, ans = 0;
  scanf("%d%d", &m, &n);
  t = n + m;
  for (int k, l = 1, r; l <= t; l = r + 1) {
    k = t / l, r = t / k;
    if (k > m || k > n) continue;
    la = (n + k) / (k + 1), ha = n / k;
    lb = (m + k) / (k + 1), hb = m / k;
    if (la <= ha && lb <= hb)
      ans += max(0, min(ha + hb, r) - max(la + lb, l) + 1);
  }
  printf("%d", ans);
}
