#include <bits/stdc++.h>
int main() {
  int n, m, i, j, count, max;
  while (scanf("%d %d", &n, &m) != EOF) {
    count = 0;
    max = n;
    if (max < m) max = m;
    for (i = 0; i <= max; i++) {
      for (j = 0; j <= max; j++) {
        if ((i * i + j) == n && (i + j * j) == m) {
          count++;
        }
      }
    }
    printf("%d\n", count);
  }
}
