Language: C++

#include<bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
#define R(i,a,n) for(int i=a;i>n;i--)
using namespace std ;
int main(){
  int a,b;
  while(cin>>a>>b,a){
    int aa[a/2+1][2],bb[b/2+1][2],c=0,cc=0;
    bool ac[10001],bc[10001];
    r(i,0,10001)ac[i]=0;
    r(i,0,10001)bc[i]=0;
    r(i,1,a){
      if(!ac[i]&&a%i==0)R(j,a,0){
	if(i*j==a){
	  aa[c][0]=i;
	  ac[i]=1;ac[j]=1;
	  aa[c++][1]=j;
	  break;
	}
      }
    }
    r(i,1,b){
      if(!bc[i]&&b%i==0)R(j,b,0){
	if(i*j==b){
	  bb[cc][0]=i;
	  bc[i]=1;bc[j]=1;
	  bb[cc++][1]=j;
	  break;
	}
      }
    }//cout<<bb[0][0]<<bb[0][1];
    int l[7];
    long long m=9999999999999;
    r(i,0,c){
      r(j,0,cc){
	int t[4];
	t[0]=aa[i][0];t[1]=aa[i][1];
	t[2]=bb[j][0];t[3]=bb[j][1];
	sort(t,t+4);p=0;
	r(i,0,3){
	  r(j,i+1,4){
	    l[p++]=t[j]-t[i];
	  }
	}
	sort(l,l+p);
	m=min(m,l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);
      }
    }
    //if(m==100000000)m=0;
    cout<<m<<endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:39:21: error: 'p' was not declared in this scope
   39 |         sort(t,t+4);p=0;
      |                     ^
a.cc:46:14: error: no matching function for call to 'min(long long int&, int)'
   46 |         m=min(m,l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:46:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   46 |         m=min(m,l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:46:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   46 |         m=min(m,l[0]*l[0]+l[1]*l[1]+l[2]*l[2]);
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~