#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int T; cin >> T; rep(_,T) { ll X,A; cin >> X >> A; ll ans = 8e18; for(ll i = 1; i <= A; i++) { ll FLOOR = A / i; ll CEIL = A / i + 1; ll FLOOR_CNT = i - A % i; ll CEIL_CNT = A % i; ll COST = 0; COST += FLOOR * FLOOR * FLOOR_CNT; COST += CEIL * CEIL * CEIL_CNT; COST += X * (FLOOR_CNT + CEIL_CNT); assert(FLOOR * FLOOR_CNT + CEIL * CEIL_CNT == A); ans = min(ans, COST); } cout << ans << "\n"; } }