#include <bits/stdc++.h>
using namespace std;
int a, b;
int get_num(double xx, double yy) { return (int)yy - (int)(xx - 1e-10); }
int main() {
  scanf("%d%d", &a, &b);
  int ans = 0;
  for (int i = 1; i <= sqrt(a + b); i++) {
    int temp = (a + b) / i,
        aa = get_num((double)a / (temp + 1), (double)a / temp),
        bb = get_num((double)b / (temp + 1), (double)b / temp);
    if (a / temp + b / temp == i && aa && bb && temp > (int)sqrt(a + b)) ans++;
    aa = get_num((double)a / (i + 1), (double)a / i),
    bb = get_num((double)b / (i + 1), (double)b / i);
    if (aa && bb) {
      ans += aa + bb - 1;
      if (a % (i + 1) == 0 && b % (i + 1) == 0) ans--;
    }
  }
  printf("%d\n", ans);
  return 0;
}
