#include<iostream>
#include<algorithm>
#define sq(a) ((a)*(a))
#define INFTY (1<<30)
using namespace std;
int main(){
	while(true){
		int ans = INFTY;
		int s[4];
		int a,b;
		scanf("%d%d", &a, &b);
		if( a==0 && b==0 ) break;
		for(int i = 1; i <= a; ++i){
			if( a % i == 0 ){
				for(int j = 1; j <= b; ++j){
					if( b % j == 0 ){
						s[0] = i;
						s[1] = a / i;
						s[2] = j;
						s[3] = b / j;
						sort(s, s+4);
						int sum = sq(s[3]-s[2])+sq(s[2]-s[1])+sq(s[1]-s[0]);
						/*for(int k = 0; k < 4; ++k){
							for(int l = 0; l < 4; ++l){
								if( k == l )continue;
								for(int m = 0; m < 4; ++m){
									if( l == m || k == m ) continue;
									for(int n = 0; n < 4; ++n){
										if( l == n || k == n || m == n )continue;
										int sum = sq(s[k]-s[l]) + sq(s[l]-s[m]) + sq(s[m]-s[n]);
										ans = min(ans, sum);
									}
								}
							}
						}*/
						ans = min(ans, sum);
					}
				}
			}
		}
		printf("%d\n", ans);
	}
}