#include <bits/stdc++.h>
using ll = long long;
using namespace std;
long long int issorted(long long int a[], long long int n) {
  if (n == 1) return 1;
  return (a[n - 1] < a[n - 2]) ? 0 : issorted(a, n - 1);
}
long long int count(string s) {
  long long int ans = 1, i, j;
  for (i = 1; i < s.length(); i++) {
    for (j = 0; j < i; j++) {
      if (s[i] == s[j]) break;
    }
    if (i == j) ans++;
  }
  return ans;
}
bool isvowel(char ch) {
  string s = "aeiouAEIOU";
  for (char c : s) {
    if (c == ch) {
      return true;
    }
  }
  return false;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
struct interval {
  int start, end;
};
bool compare(interval x, interval y) { return (x.start < y.start); }
bool isSubstring(string s1, string s2) {
  int M = s1.length();
  int N = s2.length();
  for (int i = 0; i <= N - M; i++) {
    int j;
    for (j = 0; j < M; j++)
      if (s2[i + j] != s1[j]) break;
    if (j == M) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long int n, m, count = 0;
  cin >> n >> m;
  for (long long int i = 0; i <= sqrt(max(n, m)); i++) {
    for (long long int j = 0; j <= sqrt((n, m)); j++) {
      if ((i * i) + j == n && (i + (j * j)) == m) count++;
    }
  }
  cout << count << endl;
}
