#include using namespace std; using uint = unsigned int; using ll = long long; #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CIN( LL , A ) LL A; cin >> A #define GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( remove_const::type >::type VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOREQ( VAR , INITIAL , FINAL ) for( remove_const::type >::type VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << "\n"; QUIT #define MIN( A , B ) ( A < B ? A : B ) #define MAX( A , B ) ( A < B ? B : A ) template inline T Absolute( const T& a ){ return a > 0 ? a : - a; } int main() { UNTIE; CIN( int , T ); ll X; ll A; ll A_q; ll A_q_p; ll A_r; ll hmt; ll K; ll answer; ll answer_current; REPEAT( T ){ cin >> X >> A; answer = A * A + X; FOREQ( hmt , 1 , A ){ A_q = A / hmt; A_q_p = A_q + 1; A_r = A % hmt; answer_current = A_r * ( A_q_p * A_q_p + X ) + ( hmt - A_r ) * ( A_q * A_q + X ); answer = MIN( answer , answer_current ); } cout << answer << "\n"; } QUIT; }