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