#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  int maxval = max(n, m);
  int ans = 0;
  for (int i = 0; i <= maxval; ++i) {
    for (int j = 0; j <= maxval; ++j) {
      if (i * i + j == n && i + j * j == m) ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
