#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 ); int X; int A; int A_r; int K; int answer0; int answer1; REPEAT( T ){ cin >> X >> A; if( X == 0 ){ cout << A << "\n"; } else if( X == 1 ){ cout << 2 * A << "\n"; } else { K = 0; while( K * K < X ){ K++; } K--; A_r = A % K; answer0 = A / K * ( K * K + X ) + ( A_r == 0 ? 0 : A_r * A_r + X ); K++; A_r = A % K; answer1 = A / K * ( K * K + X ) + ( A_r == 0 ? 0 : A_r * A_r + X ); cout << MIN( answer0 , answer1 ) << "\n"; } } QUIT; }