#include <bits/stdc++.h>
using namespace std;
namespace ssn {
void ios_base() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void endl() { cout << '\n'; }
template <typename E>
void Erase_To(E& R, int To) {
  for (int i = 0; i <= To; i++) {
    R.erase(R.begin());
  }
  return;
}
void setprecision(int x) { cout << std::setprecision(x) << fixed; }
template <typename E>
void Erase_From(E& R, int To) {
  for (int i = 0; i < To; i++) {
    R.erase(R.end() - 1);
  }
  return;
}
void End() { exit(0); }
template <typename E>
int Sum_Of_Elements(E x) {
  int Sum = 0;
  int Size = x.size();
  for (int i = 0; i < Size; i++) Sum += x[i];
  return Sum;
}
template <typename E1, typename N2>
int binary_search(E1 S, N2 F) {
  long long First = 0;
  long long Last = (S.size()) - 1;
  long long Mid = (First + Last) / 2;
  while (!S.empty()) {
    First = 0;
    Last = (S.size()) - 1;
    Mid = (First + Last) / 2;
    if (S[Mid] == F) {
      return Mid;
    } else if (S[Mid] > F) {
      long long Erase = (Last - Mid);
      Erase_From(S, Erase);
    } else if (S[Mid] < F) {
      long long Erase = Mid;
      Erase_To(S, Erase);
    }
  }
  return -1;
}
}  // namespace ssn
template <typename _T>
class box {
 private:
  int capacity;
  _T* arr = new _T[capacity];

 public:
  box() {
    capacity = 0;
    arr = new _T[capacity];
  }
  box(int capacity) {
    this->capacity = capacity;
    arr = new _T[capacity];
  }
  _T& operator[](int index) { return arr[index]; }
  int size() { return capacity; }
  void push_back(_T type) {
    _T* newarr = new _T[capacity + 1];
    for (int i = 0; i < capacity; i++) {
      newarr[i] = arr[i];
    }
    newarr[capacity] = type;
    arr = newarr;
    capacity++;
  }
  void push_front(_T type) {
    capacity++;
    _T* newarr = new _T[capacity];
    for (int i = 1; i < capacity; i++) {
      newarr[i] = arr[i - 1];
    }
    newarr[0] = type;
    arr = new _T[capacity];
    arr = newarr;
  }
  bool empty() { return capacity == 0 ? true : false; }
  void pop(int index) {
    _T* newarr = new _T[capacity - 1];
    for (int i = 0; i < index; i++) {
      newarr[i] = arr[i];
    }
    for (int i = index; i < capacity - 1; i++) {
      newarr[i] = arr[i + 1];
    }
    delete[] arr;
    capacity -= 1;
    arr = newarr;
  }
  void push_in(_T type, int index) {
    _T* newarr = new _T[capacity + 1];
    for (int i = 0; i < index; i++) {
      newarr[i] = arr[i];
    }
    for (int i = index + 1; i < capacity + 1; i++) {
      if (i - 1 > capacity - 1)
        capacity++;
      else
        newarr[i] = arr[i - 1];
    }
    newarr[index] = type;
    capacity++;
    delete[] arr;
    arr = newarr;
  }
  void pop_front() {
    _T* newarr = new _T[capacity - 1];
    for (int i = 0; i < capacity - 1; i++) {
      newarr[i] = arr[i + 1];
    }
    delete[] arr;
    capacity--;
    arr = newarr;
  }
  void pop_back() { capacity--; }
  _T front() { return arr[0]; }
  _T back() { return arr[capacity - 1]; }
  void clear() {
    capacity = 0;
    _T* newarr = new _T[capacity];
    delete[] arr;
    arr = newarr;
  }
  _T* begin() { return &arr[0]; }
  _T* end() { return &arr[capacity]; }
  void print() {
    if (capacity == 0) {
      return;
    }
    for (int i = 0; i < capacity; i++) {
      cout << arr[i] << " ";
    }
  }
  void unique() {
    vector<int> G;
    int newcapacity = 0;
    int newindex = 0;
    for (int i = 0; i < capacity; i++) {
      if (i + 1 == capacity) {
        G.push_back(arr[i]);
      } else {
        if (arr[i] == arr[i + 1])
          ;
        else {
          G.push_back(arr[i]);
        }
      }
    }
    _T* newarr = new _T[G.size()];
    for (int i = 0; i < G.size(); i++) {
      newarr[i] = G[i];
    }
    arr = new _T[G.size()];
    arr = newarr;
    capacity = G.size();
  }
  void like_set() {
    set<_T> c;
    int Old_Size = 0, index = 0;
    _T* newarr = new _T[capacity];
    for (int i = 0; i < capacity; i++) {
      c.insert(arr[i]);
      if (c.size() != Old_Size) {
        Old_Size++;
        newarr[index] = arr[i];
        index++;
      }
    }
    arr = newarr;
    capacity = c.size();
  }
};
enum Switch { on, off };
using namespace std;
using namespace ssn;
int32_t main() {
  long long n, m, Answer = 0;
  cin >> n >> m;
  long long a, b;
  for (a = 0; a * a <= n; a++) {
    long long b = n - a * a;
    if (a + b * b == m) Answer++;
  }
  cout << Answer;
  return 0;
}
