QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#89938 | #5817. 小学生数学题 | sunxuanyu | 100 ✓ | 803ms | 416136kb | C++14 | 1.1kb | 2023-03-21 20:20:57 | 2023-03-21 20:21:00 |
Judging History
answer
#include<iostream>
using namespace std;
#define LL long long
const int mod = 998244353,maxn = 2e7 + 10;
int sq(int x,int m){
return 1ll * x * x % m;
}
int qp(LL a,int k){
LL ans = 1;
while(k)
{
if(k&1) ans = ans * a % mod;
a = a * a % mod;
k >>= 1;
}
return ans;
}
bool num[maxn];
int prime[maxn],sm[maxn],cnt,t[maxn],s[maxn],sv[maxn],inv[maxn];
int main(){
int n,k;
cin >> n >> k;
for(int i = 2;i <= n;i++){
if(!num[i])prime[++cnt] = i;
for(int j = 1;j <= cnt && i * prime[j] <= n;j++){
num[i*prime[j]] = 1;
sm[i*prime[j]] = prime[j];
if(!(i % prime[j]))break;
}
}
for(int i = 1;i <= n;i++)
if(!num[i])t[i] = qp(i,k);
else t[i] = 1ll * t[sm[i]] * t[i/sm[i]] % mod;
s[0] = 1;
for(int i = 1;i <= n;i++)
s[i] = 1ll * s[i - 1] * t[i] % mod;
sv[n] = qp(s[n],mod - 2);
for(int i = n;i >= 1;i--)
sv[i - 1] = 1ll * sv[i] * t[i] % mod;
for(int i = 1;i <= n;i++)
inv[i] = 1ll * sv[i] * s[i - 1] % mod;
int ans = 0,x = 1;
for(int i = 1;i <= n;i++){
x = 1ll * x * i % mod;
ans = (ans + 1ll * x * inv[i]) % mod;
}
cout << ans;
}
詳細信息
Test #1:
score: 10
Accepted
time: 323ms
memory: 200376kb
input:
9450395 1
output:
688545438
result:
ok single line: '688545438'
Test #2:
score: 10
Accepted
time: 267ms
memory: 191836kb
input:
8978812 1
output:
334565356
result:
ok single line: '334565356'
Test #3:
score: 10
Accepted
time: 296ms
memory: 190804kb
input:
8944235 1
output:
982802915
result:
ok single line: '982802915'
Test #4:
score: 10
Accepted
time: 250ms
memory: 151924kb
input:
7081118 3
output:
599009773
result:
ok single line: '599009773'
Test #5:
score: 10
Accepted
time: 253ms
memory: 168916kb
input:
7904241 3
output:
871243720
result:
ok single line: '871243720'
Test #6:
score: 10
Accepted
time: 340ms
memory: 210892kb
input:
9921275 3
output:
549818101
result:
ok single line: '549818101'
Test #7:
score: 10
Accepted
time: 759ms
memory: 369048kb
input:
17575748 14135489
output:
69236780
result:
ok single line: '69236780'
Test #8:
score: 10
Accepted
time: 803ms
memory: 416136kb
input:
19858362 14822524
output:
239890381
result:
ok single line: '239890381'
Test #9:
score: 10
Accepted
time: 727ms
memory: 396272kb
input:
18848696 15530895
output:
88125041
result:
ok single line: '88125041'
Test #10:
score: 10
Accepted
time: 716ms
memory: 373988kb
input:
17787945 13890407
output:
989967864
result:
ok single line: '989967864'
Extra Test:
score: 0
Extra Test Passed