#include<stdio.h>

int minof(int min, int x) {
  min = (min < x) ? min:x;
  return min;
}

int pow2(int s, int n) {
  if(n == 28) {
    return s;
  };
  return pow2(s * 2, n + 1);
}

int slovei(int, int);
int slovei(int a, int b) {
  int i, j, k, l, o, p, min, temp, d[4] = {};
  min = pow2(2, 1);
  for(i = 1; i <= a; i += 1) {
    for(k = 1; k <= b; k += 1) {
      if(a % i == 0) {
        j = a / i;
        d[0] = i;
        d[1] = j;
      };
      if(b % k == 0) {
        l = b / k;
        d[2] = k;
        d[3] = l;
        for(o = 0; o < 3; o += 1) {
          for(p = 3; p >= o; p -= 1) {
            if(d[p] < d[p - 1]) {
             temp = d[p];
             d[p] = d[p - 1];
             d[p - 1] = temp;
            };
          };
        };
        min = minof(min, (d[1] - d[0]) * (d[1] - d[0]) + (d[2] - d[1]) * (d[2] - d[1]) + (d[3] - d[2]) * (d[3] - d[2]));
      };
    };
  };
  return min;
}

int main() {
  int a, b;

  while(1) {
    scanf("%d %d", &a, &b);
    if(a == 0 && b == 0) {
      break;
    };
    printf("%d\n", slovei(a, b));
  };

  return 0;
}