#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i <= n && i <= m; i++) {
    for (int k = 0; k <= n && k <= m; k++) {
      if ((i * i) + k == n && i + (k * k) == m) cnt++;
    }
  }
  cout << cnt;
}
