#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m, count = 0;
  cin >> n >> m;
  int minimum = min(n, m);
  for (int i = 0; i < minimum + 1; i++) {
    for (int j = 0; j < minimum + 1; j++) {
      long long int ans1 = (i * i) + j;
      long long int ans2 = i + (j * j);
      if (ans1 == n && ans2 == m) {
        count++;
      }
    }
  }
  cout << count;
  return 0;
}
