#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][0]==0){ long k=i; for(long j=i*i>>1;j>1]%MD; }else if(sieve[a>>1][0]){ r=(unsigned long)pwmemo[sieve[a>>1][0]]*(unsigned long)pwmemo[sieve[a>>1][1]]%MD; }else{ r=1; unsigned long b=a; while(n){ if(n&1){ r=r*b%MD; } n>>=1; b=b*b%MD; } } pwmemo[a]=r; return r; } main(){ mksieve(); 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); }