QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89088#5817. 小学生数学题cjd5760 637ms404448kbC++141.2kb2023-03-18 20:52:142023-03-18 20:52:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-18 20:52:15]
  • 评测
  • 测评结果:60
  • 用时:637ms
  • 内存:404448kb
  • [2023-03-18 20:52:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353, maxn = 2e7 + 10;
int pr[maxn], cnt, pw[maxn], n, k, inv[maxn], s[maxn], sv[maxn];
bitset<maxn>isp;
inline int qmul(int a, int b){
	int res = a * b - (int)((long double)a / mod * b + 1e-8) * mod;
	return res < 0 ? res + mod : res;
}
int qpow(int a, int b) {
	int ret = 1;
	while (b) {
		if (b & 1)ret = qmul(ret, a);
		a = qmul(a, a); b >>= 1;
	}
	return ret;
}
void init() {
	isp.set();
	isp[0] = isp[1] = 0;
	pw[1] = 1;
	for (int i = 1; i < maxn; ++i) {
		if (isp[i]) {
			pw[i] = qpow(i, k);
			pr[cnt++] = i;
		}
		for (int j = 0; j < cnt && pr[j] * i < maxn; ++j) {
			isp[pr[j] * i] = 0;
			pw[pr[j] * i] = qmul(pw[pr[j]], pw[i]);
			if (i % pr[j] == 0) {
				break;
			}
		}
	}
	s[0] = 1;
	for (int i = 1; i <= n; ++i) s[i] = s[i - 1] * pw[i] % mod;
	sv[n] = qpow(s[n], mod - 2);
	for (int i = n; i >= 1; --i) sv[i - 1] = sv[i] * pw[i] % mod;
	for (int i = 1; i <= n; ++i) inv[i] = sv[i] * s[i - 1] % mod;

}
signed main() {
	cin >> n >> k;
	init();
	int fac = 1, ans = 0;
	for (int i = 1; i <= n; ++i) {
		fac = qmul(fac, i);
		(ans += qmul(fac, inv[i])) %= mod;
	}
	cout << ans;
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 569ms
memory: 393464kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 632ms
memory: 382356kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 630ms
memory: 381608kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 546ms
memory: 337892kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 582ms
memory: 357176kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 637ms
memory: 404448kb

input:

9921275 3

output:

549818101

result:

ok single line: '549818101'

Test #7:

score: 0
Time Limit Exceeded

input:

17575748 14135489

output:


result:


Test #8:

score: 0
Time Limit Exceeded

input:

19858362 14822524

output:


result:


Test #9:

score: 0
Time Limit Exceeded

input:

18848696 15530895

output:


result:


Test #10:

score: 0
Time Limit Exceeded

input:

17787945 13890407

output:


result: