#include <bits/stdc++.h>
using namespace std;
bool binarysearch(int a[], int x, int n) {
  int beg = 0, end = n - 1, mid = (beg + end) / 2;
  while (beg <= end) {
    mid = (beg + end) / 2;
    if (a[mid] == x)
      return true;
    else if (a[mid] > x)
      end = mid - 1;
    else
      beg = mid + 1;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, ans = 0;
  cin >> n >> m;
  int a[32];
  int b[32];
  vector<pair<int, int> > c, d;
  for (int i = 0; i < 32; i++) {
    a[i] = i * i;
    b[i] = i;
  }
  for (int i = 0; i < 32; i++) {
    if (a[i] <= n && binarysearch(b, n - a[i], 32)) {
      c.push_back(make_pair(i, n - a[i]));
    } else if (a[i] > n)
      break;
  }
  for (int i = 0; i < 32; i++) {
    if (a[i] <= m && binarysearch(b, m - a[i], 32))
      d.push_back(make_pair(m - a[i], i));
    else if (a[i] > m)
      break;
  }
  for (int i = 0; i < c.size(); i++) {
    for (int j = 0; j < d.size(); j++) {
      if (c[i].first == d[j].first && c[i].second == d[j].second) ans++;
    }
  }
  cout << ans;
}
