#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  int count = 0;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < m; b++) {
      if ((a * a) + b == n && a + (b * b) == m) count++;
    }
  }
  if (n == 1 && m == 1) {
    cout << 2 << endl;
    return 0;
  }
  cout << count << endl;
  return 0;
}
