#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, inf = 0x3f3f3f3f;
int a, b;
int main() {
  scanf("%d%d", &a, &b);
  int ans = 0;
  for (int l = 1, r, k; l <= a + b; l = r + 1) {
    k = (a + b) / l, r = (a + b) / k;
    int L1 = (a + k) / (k + 1), R1 = a / k;
    int L2 = (b + k) / (k + 1), R2 = b / k;
    if (L1 <= R1 && L2 <= R2) ans += min(R1 + R2, r) - max(L1 + L2, l) + 1;
  }
  printf("%d\n", ans);
  return 0;
}
