QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#91270#5817. 小学生数学题skittles1412100 ✓629ms158536kbC++171.8kb2023-03-28 08:06:082023-03-28 08:06:12

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-28 08:06:12]
  • 评测
  • 测评结果:100
  • 用时:629ms
  • 内存:158536kb
  • [2023-03-28 08:06:08]
  • 提交

answer

#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

constexpr long mod = 998244353;

long bpow(long base, long exp) {
    long ans = 1;
    while (exp) {
        if (exp & 1) {
            ans = (ans * base) % mod;
        }
        base = (base * base) % mod;
        exp >>= 1;
    }
    return ans;
}

void solve() {
    int n, k;
    cin >> n >> k;
    int pfact[n + 1] {}, ppow[n + 1];
    pfact[1] = 1;
    for (int i = 2; i <= n; i++) {
        if (pfact[i]) {
            continue;
        }
        pfact[i] = i;
        if (long(i) * i > n) {
            continue;
        }
        for (int j = i * i; j <= n; j += i) {
            if (!pfact[j]) {
                pfact[j] = i;
            }
        }
    }
    long fact = 1, ans = 0;
    for (int i = 1; i <= n; i++) {
        fact = (fact * i) % mod;
        if (pfact[i] == i) {
            ppow[i] = int(bpow(i, mod - 1 - k));
        } else {
            ppow[i] = int(long(ppow[pfact[i]]) * ppow[i / pfact[i]] % mod);
        }
        ans = (ans + fact * ppow[i]) % mod;
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 291ms
memory: 77336kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 266ms
memory: 73668kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 250ms
memory: 73208kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 203ms
memory: 58844kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 226ms
memory: 65144kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 280ms
memory: 80944kb

input:

9921275 3

output:

549818101

result:

ok single line: '549818101'

Test #7:

score: 10
Accepted
time: 561ms
memory: 140684kb

input:

17575748 14135489

output:

69236780

result:

ok single line: '69236780'

Test #8:

score: 10
Accepted
time: 629ms
memory: 158536kb

input:

19858362 14822524

output:

239890381

result:

ok single line: '239890381'

Test #9:

score: 10
Accepted
time: 611ms
memory: 150588kb

input:

18848696 15530895

output:

88125041

result:

ok single line: '88125041'

Test #10:

score: 10
Accepted
time: 575ms
memory: 142364kb

input:

17787945 13890407

output:

989967864

result:

ok single line: '989967864'

Extra Test:

score: 0
Extra Test Passed