#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
unsigned long long int fexpo(unsigned long long int a,
                             unsigned long long int b) {
  if (b == 0) return 1LL;
  if (b == 1) return a;
  if (b == 2) return a * a;
  if (b % 2 == 0)
    return fexpo(fexpo(a, b / 2), 2);
  else
    return a * fexpo(fexpo(a, (b - 1) / 2), 2);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m, n;
  cin >> m >> n;
  int small = min(m, n);
  int big = max(n, m);
  int ss = sqrt(small);
  int sb = sqrt(big);
  int b;
  int asn = 0;
  for (int a = 0; a <= 1000; a++) {
    b = m - a * a;
    if (b >= 0)
      if (a + (b * b) == n) asn++;
  }
  cout << asn << endl;
}
