QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89231#5817. 小学生数学题sunxuanyu60 396ms209520kbC++231.4kb2023-03-19 12:17:562023-03-19 12:18:13

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-19 12:18:13]
  • 评测
  • 测评结果:60
  • 用时:396ms
  • 内存:209520kb
  • [2023-03-19 12:17:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353,maxn = 2e7 + 10;
int sq(int x,int m){
	return 1ll * x * x % m;
}
int qp(int a,int k,int m){
	if(!k)return 1;
	int t = sq(qp(a,k >> 1,m),m);
	if(k & 1)return 1ll * t * a % m;
	return t;
}
bool num[maxn];
int prime[maxn],sm[maxn],cnt,t[maxn],s[maxn],sv[maxn],inv[maxn];
inline int read(){
    char c = getchar();
    while(c < '0' || c > '9')c = getchar();
    int a = 0;
    while(c >= '0' && c <= '9'){
        a = a * 10 + c - '0';
        c = getchar();
    }
    return a;
}
void write(int n){
    if(!n)return;
    write(n / 10);
    putchar(n % 10 + '0');
}
int main(){
	int n = read(),k = read();
	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,mod);
		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,mod);
	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;
	}
	write(ans);
}

詳細信息

Test #1:

score: 10
Accepted
time: 344ms
memory: 199588kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 396ms
memory: 189852kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 309ms
memory: 189108kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 252ms
memory: 150516kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 288ms
memory: 167456kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 332ms
memory: 209520kb

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: