#include using namespace std; #define int long long signed main(){ int T; cin>>T; for(int i=0;i>A>>X; swap(A,X); int ans = 1e18; for(int j=1;j<=A;j++){ int now = j*X; int a = A/j; int b = A%j; now += a*a*(j-b)+(a+1)*(a+1)*b; ans = min(ans,now); } cout<