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