Skip to content

Commit a7dcbb7

Browse files
Create 1205E.cpp
1 parent c2c5034 commit a7dcbb7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

CodeForces/1205E.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
6+
const int mxN=1e5, M=1e9+7;
7+
int n, k;
8+
ll pk[mxN], mb[mxN], ans;
9+
bool c[mxN];
10+
11+
ll iv(ll a, ll m) {
12+
return a<2?1:(1-iv(m%a, a)*m)/a+m;
13+
}
14+
15+
int main() {
16+
ios::sync_with_stdio(0);
17+
cin.tie(0);
18+
19+
cin >> n >> k;
20+
pk[1]=iv(k, M);
21+
for(int i=2; i<n; ++i)
22+
pk[i]=pk[i-1]*pk[1]%M;
23+
fill(mb, mb+n, 1);
24+
for(int i=2; i<n; ++i) {
25+
if(c[i])
26+
continue;
27+
for(int j=i; j<n; j+=i) {
28+
if(j/i%i)
29+
mb[j]=mb[j]*(M-1)%M;
30+
else
31+
mb[j]=0;
32+
c[j]=1;
33+
}
34+
}
35+
for(int i=1; i<n; ++i) {
36+
for(int t=i; t<2*n-1; t+=i) {
37+
for(int s=t; s<2*n-1; s+=t) {
38+
int g=s/t, l=max(t-(n-1)/g-1, 0), r=min(t-1, (n-1)/g);
39+
if(l<r&&g<n)
40+
ans=(ans+(r/i-l/i)*pk[n-max(s-n, g)]%M*mb[i])%M;
41+
}
42+
}
43+
}
44+
cout << ans;
45+
}

0 commit comments

Comments
 (0)