QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200565 | #5040. Dirichlet $k$-th root | vanthoci# | WA | 968ms | 16920kb | C++17 | 3.4kb | 2023-10-04 17:33:29 | 2023-10-04 17:33:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
inline char nc() { static char buf[1000000], * p1 = buf, * p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; }
inline void read(int &sum) { char ch = nc(); sum = 0; while (!(ch >= '0' && ch <= '9')) ch = nc(); while (ch >= '0' && ch <= '9') sum = (sum << 3ll) + (sum << 1ll) + (ch - 48ll), ch = nc(); }
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 = 1E5 + 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], G[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));
}
#include<bits/extc++.h>
unordered_map<int, int> occ;
int nowval = 0;
void calc() {
int g = 1, fm = 1, sum = 0;
for (auto [d, t] : occ) {
if(!t) continue;
g = mul(g, power(a[d], t));
fm = mul(fm, G[t]);
sum += t;
}
nowval = add(nowval, mul(mul(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;
read(n), read(k);
for (int i = 1; i <= n; i++) read(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);
}
G[N-1] = inv(F[N-1]);
for (int i = N - 2; i >= 0; i--) G[i] = mul(G[i+1], i+1);
int ink = inv(k);
a[1] = 1;
for (x = 2; x <= n; x++) {
occ.clear();
nowval = 0;
dfs(0, 0, x);
a[x] = (b[x] - nowval) % mod;
a[x] = (a[x] + mod) % mod;
a[x] = mul(a[x], ink);
}
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: 0ms
memory: 8040kb
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: 4ms
memory: 8716kb
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: 0ms
memory: 7800kb
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: 4ms
memory: 8092kb
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: 0
Accepted
time: 956ms
memory: 16704kb
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:
1 509298944 768210156 31397754 759101893 80740356 561826331 862564382 840871048 446523741 777685542 905264255 546338384 287746596 545833689 176159038 430279667 722628961 663972399 508456777 441637678 818668691 582753500 541766927 890058957 59127138 430432227 600528851 861723556 273962920 444195967 5...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 952ms
memory: 16844kb
input:
100000 502307450 1 540668409 119623054 116071836 120600807 346207724 47536376 79941053 862397537 820627732 668027113 27933346 656896610 665891333 404013641 514893564 82214661 386300720 576212991 963482301 854395202 791877303 936919291 27551719 73799517 698613733 616454017 662657808 568860734 5100178...
output:
1 29397587 68079001 227011963 335555431 179610068 564373326 591974259 297462962 671073989 130099298 20602529 499052731 789131971 131177405 68251218 168637126 308935104 761320847 11492624 684312520 192804286 100278257 294091430 806036635 34791937 244136594 61314817 335385399 580637430 387690058 40939...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 955ms
memory: 16624kb
input:
100000 823217882 1 688169212 886236599 793541788 41483173 958042134 193277563 46217199 412123863 855202402 37986287 58306041 334222218 325091057 170387710 422003708 712358703 469639331 536518370 646455126 142072071 833996723 583979442 225064647 861003925 766761809 729406188 479825257 567264230 21738...
output:
1 633236496 764521523 761112605 394195434 436178690 568134997 352779681 464461248 33021710 897762819 395684092 449283588 372540875 74992895 471311278 118599223 436454539 414391537 610483622 263227988 961056409 51203898 159210877 382190391 156399854 506036525 158931210 621767611 510653019 490488149 6...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 951ms
memory: 16812kb
input:
100000 842138426 1 835670016 352615906 702995900 494583936 801860706 503054821 314483229 658104657 285797304 104199929 784933206 11547825 680545250 468980177 329113852 876476789 20759543 798813633 493464022 729983178 343897746 231039592 120587692 347974096 834909885 842358359 461028777 33449327 9230...
output:
1 428618194 64930015 596704138 641390448 755418756 862328911 396473870 526667378 866135366 115123418 521489737 786084895 220187038 764729928 783259994 243165548 453438954 85012193 535294230 663124340 460360352 471715560 24257502 69521429 787301501 791848 34617813 99335367 215602447 191796428 4413502...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 961ms
memory: 16712kb
input:
100000 466794394 1 983170819 351213612 382221499 947684700 809715349 950785893 582749259 207830982 18382090 472403456 815305902 851153856 805770929 235354246 236223996 206386593 406088037 457129128 176436846 851868329 84027283 180089626 318100620 136934151 765104149 791274459 140242413 31852823 6303...
output:
1 461433575 560316619 64528383 482834448 728114145 254641720 764268297 392384526 480680495 366157369 481899172 276736180 811255414 109631574 859595296 302962338 885439049 882547077 372066189 345753111 954883634 697202605 101569302 740815176 859020253 420971229 547911091 569037878 4727610 324181964 7...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 954ms
memory: 16920kb
input:
100000 485714939 1 132427270 119582804 757701567 566577181 423305407 262318798 851015289 755801661 52956761 840606982 707724784 528479464 859235239 835936597 143334140 68514796 955452602 719424391 555664140 441535083 126146704 989430201 745842062 458112604 833252225 904226630 955654215 496282273 639...
output:
1 31183126 363172641 369346745 842179869 755437335 879003898 295426643 189780048 286636971 522853004 283238655 832396290 79705440 411347955 557367672 916410683 361952389 637903011 93982438 536110662 605968971 203135703 632652761 113697112 491304243 664310025 367625074 714664477 976680044 283085677 3...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 968ms
memory: 16736kb
input:
100000 806625371 1 581917957 420170393 436927165 323423476 267123979 874085940 121036966 3538102 481796016 210566156 738097480 205805071 984460918 300320782 280672798 698658837 342536744 981719654 704662920 727456305 634292079 636490351 943354990 641337244 901400301 18934449 936857735 796675652 3470...
output:
1 946406431 465204983 900099364 19060034 448648768 771369562 455003321 865072216 231643866 657087140 622028182 319482133 106499328 600926318 440922254 841018450 863827548 801933432 428248468 780347819 128224082 360918629 370586486 225756259 109848476 453874662 683886264 407173757 321673954 287652884...
result:
ok 100000 numbers
Test #12:
score: 0
Accepted
time: 960ms
memory: 16804kb
input:
100000 825545915 1 197200362 884794054 116152764 244305842 576968505 21582775 921521394 249518897 214380802 578769683 466480292 881375031 341670758 368684735 187782943 330558526 195646840 942025033 387635745 849341457 676411500 283550501 838878034 430297299 437329979 433876504 616071371 959115219 54...
output:
1 830654973 609877413 965729392 36037200 585827656 616607929 102255783 730671232 574383538 858096621 37793650 791262775 486740415 243179537 729043280 474844635 264467363 39063869 920371256 220707456 529178817 59473721 398475798 725020916 166928272 260722056 278753927 595148366 502557142 363853344 82...
result:
ok 100000 numbers
Test #13:
score: 0
Accepted
time: 38ms
memory: 16744kb
input:
100000 1 1 537766921 133390620 340812406 700777822 393339907 813813219 775043690 969153150 568921216 968632969 436848033 515717099 795050941 937512393 938140883 953250978 888790176 949054294 376670196 889773076 631948404 320389585 993483258 592817687 169830609 230045051 808000459 666694223 963387669...
output:
1 537766921 133390620 340812406 700777822 393339907 813813219 775043690 969153150 568921216 968632969 436848033 515717099 795050941 937512393 938140883 953250978 888790176 949054294 376670196 889773076 631948404 320389585 993483258 592817687 169830609 230045051 808000459 666694223 963387669 73009810...
result:
ok 100000 numbers
Test #14:
score: 0
Accepted
time: 26ms
memory: 16624kb
input:
100000 1 1 161595188 280891423 641399996 610231934 314222273 125413393 388566479 239174827 814902010 4963286 108797090 940354380 472376548 294722233 540478881 394335167 750918378 336138435 336975575 40527503 221615158 362509005 108325010 488340731 957035017 298193127 224698161 345907859 429572766 73...
output:
1 161595188 280891423 641399996 610231934 314222273 125413393 388566479 239174827 814902010 4963286 108797090 940354380 472376548 294722233 540478881 394335167 750918378 336138435 336975575 40527503 221615158 362509005 108325010 488340731 957035017 298193127 224698161 345907859 429572766 739457452 1...
result:
ok 100000 numbers
Test #15:
score: 0
Accepted
time: 29ms
memory: 16752kb
input:
100000 1 1 179688040 428392226 107779304 289457533 767323037 133268036 232317782 507440857 364628336 433802541 175010733 970727075 149702155 419947912 4863066 997699780 80828183 885503000 599270838 721744681 809526264 174399912 753629514 685853659 745995072 832367159 337650332 163075308 125986377 44...
output:
1 179688040 428392226 107779304 289457533 767323037 133268036 232317782 507440857 364628336 433802541 175010733 970727075 149702155 419947912 4863066 997699780 80828183 885503000 599270838 721744681 809526264 174399912 753629514 685853659 745995072 832367159 337650332 163075308 125986377 446826918 3...
result:
ok 100000 numbers
Test #16:
score: -100
Wrong Answer
time: 119ms
memory: 16740kb
input:
100000 2 1 735046526 866300308 936249189 359210886 338805532 433066347 804981764 750512701 863129266 935871059 798098463 135725371 436882481 104872951 955818061 492785493 513972718 904785728 991541119 857204342 296612487 14979136 798715619 571578701 109222873 967574413 936192081 784724576 614768723 ...
output:
1 367523263 433150154 950192272 179605443 574257378 715655350 25601333 845686111 236412941 967057706 243209382 566984862 114336796 469467496 718783639 745514923 375106383 452392864 558875474 230276772 777559333 7489568 590340225 973447251 719808273 598359702 166155883 392362288 796225756 704294713 6...
result:
wrong answer 6th numbers differ - expected: '371830072', found: '574257378'