#include <bits/stdc++.h>
using namespace std;
int a, b, ans;
int main() {
  scanf("%d%d", &a, &b);
  int len(a + b);
  for (int i = 1, r; i <= len; i = r + 1) {
    int P(len / i);
    r = len / P;
    if (P > a || P > b) continue;
    int an = (a + P) / (P + 1), ax = a / P, bn = (b + P) / (P + 1), bx = b / P;
    if (an <= ax && bn <= bx)
      ans += std::min((ax + bx), r) - std::max((an + bn), i) + 1;
  }
  printf("%d\n", ans);
  return 0;
}
