Advertisement
RaFiN_

Makoto and a Blackboard cf-1097D

Jul 3rd, 2020
1,365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. /*If you calculate the expected value for a given n with k = 1 (one step), you see that the answer is simply σ1(n) / σ0(n), where σ1(n) denotes the sum of divisors of n and σ0(n) the number of divisors.
  2.  
  3. It's well known that σ1 and σ0 are multiplicative functions (and easy to prove indeed). So, it's easy to see from there using induction that the function is multiplicative.*/
  4. // why they are multiplicative ?
  5. //coz https://cp-algorithms.com/algebra/divisors.html
  6.  
  7. ll dp[55][N];
  8. ll yo(ll v,ll p,ll k)
  9. {
  10.     if(k==0) return qpow(v,p)%mod;
  11.     ll &ret=dp[p][k];
  12.     if(ret!=-1) return ret;
  13.     ll ans=0;
  14.     for(ll i=0;i<=p;i++) ans=(ans+yo(v,i,k-1))%mod;
  15.     ans=ans*qpow(p+1,mod-2)%mod;
  16.     return ret=ans;
  17. }
  18. int main()
  19. {
  20.     BeatMeScanf;
  21.     ll i,j,k,n,m;
  22.     vpll fac;
  23.     cin>>n>>k;
  24.     for(i=2;i*i<=n;i++){
  25.         if(n%i==0){
  26.             ll p=0;
  27.             while(n%i==0) n/=i,p++;
  28.             fac.eb(i,p);
  29.         }
  30.     }
  31.     if(n>1) fac.eb(n,1);
  32.     ll ans=1;
  33.     for(auto x:fac){
  34.         mem(dp,-1);
  35.         ans=ans*yo(x.F,x.S,k)%mod;
  36.     }
  37.     cout<<ans<<nl;
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement