// O( min( N , M ) )の愚直解チェック #include using namespace std; using ll = long long; #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define FOREQ( VAR , INITIAL , FINAL ) for( TYPE_OF( FINAL ) VAR = INITIAL ; VAR <= FINAL ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT int main() { UNTIE; constexpr const ll bound = 1000000000; CIN_ASSERT( N , 1 , bound ); CIN_ASSERT( M , 1 , bound ); // sum( ll i = 1 ; i <= N ; i++ ) sum( ll j = 1 ; j <= M ; j++ ){ i % j } // = sum( ll j = 1 ; j <= M ; j++ ) sum( ll i = 1 ; i <= N ; i++ ){ i % j } // = sum( ll j = 1 ; j <= M ; j++ ){ ( N / j ) * ( ( j - 1 ) * j ) / 2 + ( N % j ) * ( N % j + 1 ) / 2 } // = sum( ll j = 1 ; j <= M ; j++ ){ ( N / j ) * ( ( j - 1 ) * j ) / 2 + ( N % j ) * ( N % j + 1 ) / 2 } constexpr const ll P = 998244353; ll answer0 = 0; ll answer1 = 0; if( M > N ){ M = N; } ll N_r; ll j_sum = 0; FOREQ( j , 1 , M ){ N_r = N % j; j_sum = ( j_sum + j - 1 ) % P; answer0 += ( ( N / j ) * j_sum ) % P; answer1 += ( N_r * ( N_r + 1 ) ) % P; } answer1 = ( answer1 % P ) * ( ( P + 1 ) / 2 ); RETURN( ( answer0 + answer1 ) % P ); }