#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double esp = 0.0000000001;
const double PI = acos(-1.0);
const int mod = 1000000007;
const int MY = (1 << 5) + 5;
const int MX = (1 << 20) + 5;
const int S = 20;
int main() {
  int n, m;
  while (~scanf("%d%d", &n, &m)) {
    int ans = 0;
    for (int i = 0; i * i <= n; ++i) {
      int b = n - i * i;
      if (b >= 0 && i + b * b == m) ans++;
    }
    printf("%d\n", ans);
  }
  return 0;
}
