#include <bits/stdc++.h>
int main() {
  int n, m, a, b, sum1, sum2, count = 0, count1 = 0;
  scanf("%d %d", &n, &m);
  if (n == 1 && m == 1) {
    printf("2\n");
  } else {
    for (a = 0;; a++) {
      sum1 = 0;
      sum2 = 0;
      for (b = 0;; b++) {
        sum1 = sum1 + a * a + b;
        sum2 = sum2 + a + b * b;
        if (sum1 > n && sum2 > m) {
          count1++;
          break;
        }
        if (sum1 > n || sum2 > m) {
          break;
        }
        if (sum1 == n && sum2 == m) {
          count++;
        }
        sum1 = 0;
        sum2 = 0;
      }
      if (count == 1) {
        printf("1\n");
        break;
      } else if (count1 == 1) {
        printf("0\n");
        break;
      }
    }
  }
  return 0;
}
