#include <bits/stdc++.h>
int main() {
  int a[1000], i, j, m, n, cnt = 0;
  scanf("%d %d", &n, &m);
  int temp, temp2;
  if (n == 1 && m == 1)
    printf("2\n");
  else {
    for (i = 0; i <= n / 2; i++) {
      temp = i * i;
      if (temp > n) break;
      temp2 = n - temp;
      if ((temp + temp2 == n) && (i + (temp2 * temp2) == m)) {
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }
  return 0;
}
