#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #define rd(v) long v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;} #define wt(v) {long _z=v;do*--wp=_z%10+48;while(_z/=10);} #define rep(v,e) for(long v=0;v>=1; a=a*a%MD; } return r; } main(){ char rwbuf[64]; read(0,rwbuf,sizeof rwbuf); char*rp=rwbuf; rd(n); rd(m); long e=n%(MD-1); long a=0; rep(d,m){ a=a+pw(d,e); } a=pw(m,e)*(m-1)%MD*(MD+1>>1)%MD-a%MD; a=a*(n%MD)%MD*(m+1)%MD; a+=a<0?MD:0; char*wp=rwbuf+sizeof rwbuf; wt(a); write(1,wp,rwbuf+sizeof rwbuf-wp); _exit(0); }