QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298241#5817. 小学生数学题liangbob100 ✓907ms188012kbC++141.5kb2024-01-05 21:10:012024-01-05 21:10:02

Judging History

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

  • [2024-01-05 21:10:02]
  • 评测
  • 测评结果:100
  • 用时:907ms
  • 内存:188012kb
  • [2024-01-05 21:10:01]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define int long long
#define endl '\n'
#define IL inline
using namespace std;
const int N = 2e7 + 10;
const int INF = 0x3f3f3f3f;

IL int read()
{
    int x = 0,f = 1;
    char c = getchar();
    while(c <'0'|| c >'9'){if(c == '-') f = -1;c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar();
    return x * f;
}

void write(int x)
{
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

int mod = 998244353;
int ny[N], p[N];
bool vis[N];

int qpow(int a, int b)
{
    int d = a % mod, ans = 1;
    while(b)
    {
        if(b & 1) ans = (ans * d) % mod;
        d = d * d % mod;
        b >>= 1;
    }
    return ans;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k, m = 0;
    cin >> n >> k;
    for(int i = 2;i <= n;i++)
    {
        if(!vis[i])
        {
            p[++m] = i;
            ny[i] = qpow(qpow(i, k), mod - 2);
        }
        for(int j = 1;p[j] * i <= n && j <= m;j++)
        {
            vis[i * p[j]] = 1;
            ny[i * p[j]] = ny[i] * ny[p[j]] % mod;
            if(i % p[j] == 0) break;
        }
    }
    int ans = 1, fac = 1;
    for(int i = 2;i <= n;i++)
    {
        fac = (fac * i) % mod;
        ans = (ans + fac * ny[i] % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 325ms
memory: 94008kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 298ms
memory: 89708kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 300ms
memory: 89176kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 248ms
memory: 71080kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 276ms
memory: 78728kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 350ms
memory: 99196kb

input:

9921275 3

output:

549818101

result:

ok single line: '549818101'

Test #7:

score: 10
Accepted
time: 797ms
memory: 168944kb

input:

17575748 14135489

output:

69236780

result:

ok single line: '69236780'

Test #8:

score: 10
Accepted
time: 907ms
memory: 188012kb

input:

19858362 14822524

output:

239890381

result:

ok single line: '239890381'

Test #9:

score: 10
Accepted
time: 881ms
memory: 179916kb

input:

18848696 15530895

output:

88125041

result:

ok single line: '88125041'

Test #10:

score: 10
Accepted
time: 818ms
memory: 170536kb

input:

17787945 13890407

output:

989967864

result:

ok single line: '989967864'

Extra Test:

score: 0
Extra Test Passed