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