# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
633654 | lkh3happy | 팔찌 (kriii4_V) | C++14 | 469 ms | 23752 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
long long mod=1e9+7, ep[1000001], mi[1000001]={1}, kp[1000001]={1};
long long po(long long x){
long long sum=1, y=mod-2;
for(;y;y>>=1, x=x*x%mod) if(y&1) sum=sum*x%mod;
return sum;
}
int main(){
long long n, k, ans=0;
scanf("%lld%lld\n", &n, &k);
for(int i=1;i<=n;i++) ep[i]=i;
for(int i=2;i<=n;i++) if(ep[i]==i) for(int j=i;j<=n;j+=i) ep[j]=ep[j]/i*(i-1);
for(int i=1;i<=n;i++) kp[i]=kp[i-1]*k%mod, ep[i]=(ep[i]*(mi[i]=po(i))+ep[i-1])%mod;
for(int i=1;i<=n;i++) ans=(ans+(kp[i]*mi[i]%mod)*ep[n/i]*2+((i&1)?kp[i/2+1]*2:kp[i/2]+kp[i/2+1]))%mod;
if(n^1) printf("%lld\n", (ans*mi[4]+1)%mod);
else printf("%lld\n", k+1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |