#include #include #include
using namespace std ;
const int mmod = 19940417 , inv6 = 3323403 ;
long long N , M ;
long long ds( long long lf , long long rg ){
return ( lf + rg ) * ( rg - lf + 1 ) / 2%mmod ;
}
long long pfs( long long lf , long long rg ){
lf = lf - 1 ;
long long tmp1 = rg * ( rg + 1 )%mmod * ( 2 * rg + 1 ) %mmod * inv6 %mmod ,
tmp2 = lf * ( lf + 1 )%mmod * ( 2 * lf + 1 ) %mmod * inv6 %mmod ;
return ( tmp1 - tmp2 + mmod )%mmod ;
}
long long cal( long long a , long long lim , long long div ){
long long rt = 0 ;
for( int i = 1 , last = 1 ; i <= lim ; i = last ){
int ed = min( div / ( div / i ) , lim ) ;
rt = ( rt + ( div / i ) * ds( last , ed ) ) %mmod ;
last = ed + 1 ;
}
return rt * a %mmod ;
}
long long spe(){
long long rt = 0 ;
for( int i = 1 , last = 1 ; i <= M ; i = last ){
int ed = min( M / ( M / i ) , N / ( N / i ) ) ;
rt = ( rt + ( M / i ) * ( N / i )%mmod * pfs( last , ed )%mmod )%mmod ;
last = ed + 1 ;
}
return rt ;
}
int main(){
long long ans1 = 0 , ans2 = 0 ;
scanf( "%lld%lld" , &N , &M ) ;
if( N < M ) swap( N , M ) ;
ans1 = N * N%mmod * M%mmod * M%mmod - cal( N*N%mmod , M , M ) - cal( M*M%mmod , N , N ) + cal( 1 , N , N ) * cal( 1 , M , M ) %mmod ;
ans1 = ( ans1%mmod + mmod )%mmod ;
ans2 = N * M%mmod * M%mmod - cal( N%mmod , M , M ) - cal( M%mmod , M , N ) + spe() ;
ans2 = ( ans2%mmod + mmod )%mmod ;
printf( "%lld" , ( ans1 - ans2 + mmod )%mmod<