#include <bits/stdc++.h>   bool local = false;   using namespace std;   template <class T>   string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   void print(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;   };   template <class T>   void print1(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x + 1 <<    ;     cout <<   n ;   };   template <class T1, class T2>   ostream &operator<<(ostream &o, pair<T1, T2> x) {     return o << x.first <<     << x.second;   }   template <class T1, class T2>   istream &operator>>(istream &o, pair<T1, T2> &x) {     return o >> x.first >> x.second;   }   template <class T1, class T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <class T1, class T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T1, class T2>   void operator+=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;   }   template <class T1, class T2>   void operator-=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;   }   int nint() {     int x;     cin >> x;     return x;   }   double getTime() { return clock() / (double)CLOCKS_PER_SEC; };   mt19937 rnd(0);   int rand(int n) { return rnd() % n; }   int rand(int l, int r) { return rnd() % (r - l + 1) + l; }   const int mod = 1000000000 + 7;   void initIO() {     if (local) {       freopen( input.txt ,  r , stdin);       srand((int)time(0));       rnd.seed((int)time(0));     } else {     }     {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     };   }   void solve();   int main() {     initIO();     int tc = 1;     for (int tt = 0; tt < (tc); tt++) {       solve();     }     if (local)       cout <<   n             <<  time =   << getTime() <<   n ;   }   long long n;   long long get(long long l, long long r) { return r - l + 1; }   const int D = 50000;   int a, b;   int check(int a1, int b1) {     if (a1 < 0 || b1 < 0) return 0;     int d = a1 + b1;     int r = n % d;     int k = n / d;     long long a2 = a1 * k;     long long b2 = b1 * k;     long long ra = a - a2;     long long rb = b - b2;     if (ra < 0 || rb < 0 || ra > a1 || rb > b1 || ra + rb > r) return 0;     return 1;   }   int getansD(int d) {     int k = n / d;     int la = a / (k + 1);     int ra = a / k;     for (int a = la; a <= ra; a++) {       int b = d - a;       if (check(a, b)) return 1;     }     return 0;   }   int get(int a, int k) {     int l = 0, r = a / k;     int ans = 0;     while (l <= r) {       int c = (l + r) / 2;       if (a / k - c >= c * (long long)k + a % k) {         ans = c;         l = c + 1;       } else         r = c - 1;     }     return ans;   }   int getansK(int k) {     int da = a / k;     int db = b / k;     if (a % k > da || b % k > db) return 0;     int ca = get(a, k);     int cb = get(b, k);     int rd = da + db;     long long l = 1, r = rd;     long long ans = rd + 1;     while (l <= r) {       long long d = (l + r) / 2;       long long res = (long long)n - d * k;       if (n / d < k || res >= d || d < (da - ca) + (db - cb)) {         l = d + 1;       } else {         ans = d;         r = d - 1;       }     }     return max(0ll, rd - ans + 1);   }   void solve() {     cin >> a >> b;     if (a > b) swap(a, b);     n = a + b;     if (a == 1) {       long long l = n / 2 + 1;       long long r = n;       cout << get(l, r) <<   n ;       return;     }     long long ans = 0;     for (int d = 1; d <= n; d++) {       int k = n / d;       if (k <= D) break;       ans += getansD(d);     }     for (int k = 1; k <= D; k++) ans += getansK(k);     cout << ans;   }