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