#include <bits/stdc++.h>
using namespace std;
int cnt[1005][1005];
void init() {
  memset(cnt, 0, sizeof(cnt));
  for (int a = 0; a <= 1000; a++)
    for (int b = 0; b <= 1000; b++) {
      int n = a * a + b;
      int m = b * b + a;
      if (n <= 1000 && m <= 1000) cnt[n][m]++;
    }
}
int main() {
  init();
  int n, m;
  while (scanf("%d%d", &n, &m) == 2) {
    printf("%d\n", cnt[n][m]);
  }
}
