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