#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<long long int> v;
  for (long long int i = 0; i <= 1000; i++) v.push_back(i * i);
  long long int count = 0;
  for (long long int i = 0; i <= n; i++) {
    long long int p = n - i;
    auto it = find(v.begin(), v.end(), p);
    if (it != v.end()) {
      long long int ind = it - v.begin();
      if (ind + i * i == m) {
        count++;
      } else
        continue;
    } else
      continue;
  }
  if (count)
    cout << count;
  else
    cout << count;
}
