#include using namespace std; using namespace chrono; #if __has_include() #include using namespace atcoder; #endif int main() { int64_t t; cin >> t; int64_t inf = (1LL << 60); for (int64_t _ = 0; _ < t; _++) { int64_t x, a; cin >> x >> a; vector dp(a + 1, inf); dp[a] = 0; for (int64_t i = a; 0 <= i; i--) { for (int64_t j = 1; j <= min(i, 320); j++) { dp[i - j] = min(dp[i - j], dp[i] + j * j + x); } } cout << dp[0] << endl; } return 0; }