#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  int solve(int a, int b) {
    int n = a + b;
    int res = 0;
    for (int l = 1, r = 1; l <= n; l = r + 1) {
      int g = n / l;
      r = n / g;
      if (g > a || g > b) {
        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) {
        continue;
      }
      res += max(0, min(r, ar + br) - max(l, al + bl) + 1);
    }
    return res;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int a, b;
  cin >> a >> b;
  cout << sol.solve(a, b) << "\n";
  return 0;
}
