Submission #20004

#TimeUsernameProblemLanguageResultExecution timeMemory
20004Namnamseo팔찌 (kriii4_V)C++14
6 / 100
1000 ms25496 KiB
#include<cstdio> typedef long long ll; ll M=int(1e9)+7; ll pow(ll x,ll y){ if(y==0)return 1; if(y==1)return x; ll o=pow(x,y/2); if(y%2==0)return o*o%M; else return o*o%M*x%M; } ll ans [1000010]; ll phi [1000010]; ll kpow[1000010]; bool sieve[1000010]; int n,k; int main(){ scanf("%d%d",&n,&k); int i,j; kpow[0]=1; kpow[1]=k; phi[1]=1; ans[1]=k; for(i=2; i<=n; ++i){ kpow[i]=kpow[i-1]*k%M; ans[i]=kpow[i]; if(!sieve[i]){ for(j=i; j<=n; j+=i){ sieve[j]=true; if(phi[j]==0) phi[j]=j; phi[j] /= i; phi[j] *= i-1; } } } for(i=2; i<=n; ++i){ for(j=i; j<=n; j+=i){ ans[j] += phi[i] * kpow[j/i]; ans[j] %= M; } } ll tmp, half=pow(2, M-2), sumans = 2; for(i=1; i<=n; ++i){ tmp = ans[i] * pow(i,M-2); sumans += tmp; sumans %= M; if(i&1){ sumans += kpow[(i+1)/2]; sumans %= M; } else { sumans += (k+1)*half%M*kpow[i/2]; sumans %= M; } } printf("%lld",sumans*half%M); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...