#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a, b;
  int count = 0;
  for (int i = 0; i <= max(n, m); i++) {
    for (int j = 0; j <= max(n, m); j++) {
      int res = i * i + j;
      int res1 = i + j * j;
      if (res == n && res1 == m) {
        count++;
      }
    }
  }
  cout << count << endl;
}
