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