QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#200498#5040. Dirichlet $k$-th rootvanthoci#TL 5ms11852kbC++173.0kb2023-10-04 17:10:502023-10-04 17:10:50

Judging History

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

  • [2023-10-04 17:10:50]
  • 评测
  • 测评结果:TL
  • 用时:5ms
  • 内存:11852kb
  • [2023-10-04 17:10:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

template<class A> string to_string(A v) {
	string res = "{";
	for (const auto &x: v) res += to_string(x) + ", ";
	return res.substr(0, res.size() - 2) + "}";
}
void debug_out() { cerr << "\n"; }
template<class H, class... T> void debug_out(H h, T... t) {
	cerr << " " << to_string(h); debug_out(t...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "] : "; debug_out(__VA_ARGS__)
#define Time_Start clock_t start = clock()
#define Time_End  clock_t end = clock();\
        double time_elapsed = (double)(end - start) / CLOCKS_PER_SEC;\
        cerr << "time elapsed :" << time_elapsed << "s\n"

const int N = 2E5 + 10;
const int mod = 998244353;
vector<int> fac[N];

int n, k, x;
int called = 0;
int a[N], b[N];
int AK[N], F[N];

unordered_map<int, int> INV;
int add(const int &a, const int& b) {
    return (a + b >= mod) ? (a + b - mod) : (a + b);
}
int mul(const int &a, const int& b) {
    return 1LL * a * b % mod;
}
int power(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = mul(a, a)) {
        if (b & 1) res = mul(res, a);
    }
    return res;
}
int inv(const int& a) {
    if(INV.count(a)) return INV[a];
    return INV[a] = power(a, mod - 2);
}
int Div(const int &a, const int& b) {
    return mul(a, inv(b));
}

unordered_map<int, int> occ;


int nowval = 0;
void calc() {
    // debug(++called, x);
    int g = 1, fm = 1, sum = 0;

    for (auto [d, t] : occ) {
        g = mul(g, power(a[d], t));
        fm = mul(fm, F[t]);
        sum += t;
    }
    if(x==4) cerr<<endl;
    nowval = add(nowval, mul(Div(AK[sum], fm), g)); 
}

void dfs(int now, int dep, int res) {
    // debug(now, dep, res, x);
    if (dep == k - 1 || res == 1) {
        if (res != x) {
            if (res != 1) occ[res]++;
            calc();
            if (res != 1) {
                occ[res]--;
                if(!occ[res]) occ.erase(res);
            }
        }
        return ;
    }
    for (int i = now; i < fac[x].size() - 1; i++) {
        int& d = fac[x][i];
        if (res % d) continue;
        occ[d] ++;
        dfs(i, dep + 1, res / d);
        occ[d] --;
        if(!occ[d]) occ.erase(d);
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    Time_Start;
    
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 2; i <= n; i++) {
        for (int j = i; j <= n; j += i) {
            fac[j].push_back(i);
        }
    }

    AK[0] = F[0] = 1;
    for (int i = 1; i < N; i++) {
        AK[i] = mul(AK[i-1], k - i + 1);
        F[i] = mul(F[i-1], i);
    } 

    a[1] = 1;
    for (x = 2; x <= n; x++) {
        nowval = 0;
        dfs(0, 0, x);
        // debug(nowval, x);
        a[x] = ((b[x] - nowval) % mod + mod) % mod;
        a[x] = Div(a[x], k);
    }
    for (int i = 1; i <= n; i++) cout << a[i] << ' ';

    debug(called);
    Time_End;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11260kb

input:

5 2
1 8 4 26 6

output:

1 4 2 5 3 

result:

ok 5 number(s): "1 4 2 5 3"

Test #2:

score: 0
Accepted
time: 5ms
memory: 11668kb

input:

1000 10
1 516238479 765833625 408427111 593035929 984641872 149832309 743527500 533342020 315774476 81082172 461044503 235289865 539969249 564590101 736090497 933661679 394417077 377363949 717587561 143428748 321957671 413061277 166846744 532438287 802900949 101236134 182814904 328306207 83339054 87...

output:

1 750394895 575705539 383612918 758074640 870483127 713754278 172378328 328377975 148157627 607054829 769165678 522651163 979451027 321052733 428161561 792137215 595294435 736507442 784558508 35541967 129771597 141130563 667029666 976562087 614420517 890540347 922620141 132655056 898078185 586990958...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 11852kb

input:

1000 10
1 836321215 611344545 176796302 574251412 137508398 761666720 357050290 801608050 863745155 811911311 829248030 265662561 683320811 920044294 338428495 840771823 558535163 926728514 375903056 522656042 909868778 153190814 812151247 960179729 591861004 169384211 295767075 841728125 81742549 5...

output:

1 582754298 560256631 598696700 656371753 428716095 76166672 762502364 234864311 233488066 380664437 883840099 326039562 115077358 562124625 491468731 982497100 88908472 292321722 938842515 680178128 840510694 214967952 569450139 579949075 97329455 173736151 491492784 583294989 144817858 358079034 9...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 5ms
memory: 11444kb

input:

1000 10
1 158159598 758845348 641419963 949731479 892599046 605485292 272562963 71629727 807736065 544496098 895461672 992289725 360646418 47025620 104802564 747881967 584699437 779838610 638198320 671654821 729764045 195310235 459211397 159448304 78831175 237532287 408719246 520941761 546171999 897...

output:

1 415113701 475182276 672451493 793744195 950229534 659495141 726381508 631317964 412740072 453747351 272892516 598351149 977147905 739966693 418651375 174612632 596342698 77983861 481155841 428325132 962771540 518653200 864432859 639266798 599162983 114398480 12687680 351567482 742362461 888336134 ...

result:

ok 1000 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

100000 483386906
1 925386004 817279817 436846237 363754513 36363197 132023702 507929492 314426859 89798592 832041984 299550534 283316534 540665653 105421174 607783420 916340928 533190624 313917727 118229052 732510050 447767998 823833186 132028675 284839462 164439702 201511962 983444172 268467355 346...

output:


result: