#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a, b, s = 0;
  cin >> n >> m;
  for (a = m; a >= 0; a--) {
    b = n - a * a;
    if (a + b * b == m && a >= 0 && b >= 0) s++;
  }
  cout << s;
  return 0;
}
