#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, count = 0;
  cin >> n >> m;
  int maxv = max(n, m);
  for (int a = 0; a <= maxv; a++) {
    for (int b = 0; b <= maxv; b++) {
      if (a * a + b == n and a + b * b == m) count++;
      if (a * a + b > n or a + b * b >= m) break;
    }
  }
  cout << count << endl;
  return 0;
}
