QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339271#5547. Short FunctionAllSolvedin1557#WA 56ms4800kbC++205.0kb2024-02-26 22:16:032024-02-26 22:16:03

Judging History

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

  • [2024-02-26 22:16:03]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:4800kb
  • [2024-02-26 22:16:03]
  • 提交

answer

// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

#define ll long long
#define MOD 998244353ll

ll pow(ll a, ll x, ll M){
    a %= M;
    if(a == 0) return 0;
    if(x == 0) return 1;
    if(x == 1) return a%M;
    ll k = pow(a, x/2, M);
    k = k*k; k %= M;
    if(x % 2 == 1){
        k *= a; k %= M;
    }
    return k;
}

ll inv2_23(ll x){
    return pow(x, (1ll<<22) - 1, (1ll<<23));
}

ll inv7(ll x){
    return pow(x, 5ll, 7ll);
}

ll inv17(ll x){
    return pow(x, 15ll, 17ll);
}

ll invMOD(ll x){
    return pow(x, MOD - 2, MOD);
}

ll phiN(ll N){
    ll cnt = 0;
    for(ll i=1; i<=N; i++){
        if(__gcd(i, N) == 1) cnt++;
    }
    return cnt;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    ll n, k; cin >> n >> k;
    vector<ll> v(n);
    for(ll i=0; i<n; i++) cin >> v[i];
    if(k <= 46){
        ll k2 = 1ll << k;
        ll r = k2 % n, G = k2 / n;
        ll pi = 1;
        for(ll i=0; i<n; i++){
            pi *= v[i]; pi %= MOD;
        }
        ll pi2 = pow(pi, G, MOD);
        ll u1 = 1;
        for(ll i=0; i<r; i++){
            u1 *= v[i]; u1 %= MOD;
        }
        vector<ll> b(n);
        b[0] = u1 * pi2 % MOD;
        for(ll i=1; i<n; i++){
            b[i] = b[i-1] * invMOD(v[i-1]) % MOD;
            b[i] = b[i] * v[(r+i-1)%n] % MOD;
        }
        for(ll i=0; i<n; i++){
            b[i] %= MOD; b[i] = (b[i] + MOD) % MOD;
        }
        for(ll i=0; i<n; i++) cout << b[i] << " ";
        cout << "\n";
        return 0;
    }

    // r = 2^k % N
    ll phi = phiN(n);
    ll k1 = k % phi;
    ll r = pow(2, k1, n);

    //cout << r << " " << r_real << " rr\n";
    ll e2 = 0;
    while(((n >> e2)&1ll) == 0) e2++;
    ll r1 = r >> e2, n1 = n >> e2;

    //cout << e2 << "\n";

    ll g1 = ((1ll << 23) - r1) * inv2_23(n1) % (1ll << 23);
    ll phi76 = 7*7*7*7*7*6, p76 = 7*7*7*7*7*7;

    ll k2 = k % phi76;
    ll A2 = pow(2, k2, p76) - r;
    A2 %= p76; A2 = (A2 + p76) % p76;
    ll n2 = n;
    while((A2 % 7 == 0) and (n2 % 7 == 0)){
        A2 /= 7; n2 /= 7;
    }
    ll g2 = A2 * inv7(n2) % 7;

    //cout << ((1ll << k) - r - G_real*n) % 7 << " mod7\n";
    //cout << A2 << " " << n2 << "\n";
    //cout << g2 << " " << G_real % 7 << "\n";
    ll phi176 = 17*17*17*17*17*16, p176 = 17*17*17*17*17*17;

    ll k3 = k % phi176;
    ll A3 = pow(2, k3, p176) - r;
    A3 %= p176; A3 = (A3 + p176) % p176;

    ll n3 = n;
    while((A3 % 17 == 0) and (n3 % 17 == 0)){
        A3 /= 17; n3 /= 17;
    }
    ll g3 = A3 * inv17(n3) % 17;

    //cout << g1 << " " << g2 << " " << g3 << "\n";
    
    //cout << G_real % (1ll << 23) << " " << G_real % 7 << " " << G_real % 17 << "\n";

    ll G = g1 * 7 * 17 * inv2_23(7*17) + g2 * (1ll << 23) * 17 * inv7((1ll << 23)*17) + g3 * 7 * (1ll << 23) * inv17(7*(1ll << 23));
    G %= 998244352ll;

    ll pi = 1;
    for(ll i=0; i<n; i++){
        pi *= v[i]; pi %= MOD;
    }
    ll pi2 = pow(pi, G, MOD);
    ll u1 = 1;
    for(ll i=0; i<r; i++){
        u1 *= v[i]; u1 %= MOD;
    }
    vector<ll> b(n);
    b[0] = u1 * pi2 % MOD;
    for(ll i=1; i<n; i++){
        b[i] = b[i-1] * invMOD(v[i-1]) % MOD;
        b[i] = b[i] * v[(r+i-1)%n] % MOD;
    }
    for(ll i=0; i<n; i++){
        b[i] %= MOD; b[i] = (b[i] + MOD) % MOD;
    }
    for(ll i=0; i<n; i++) cout << b[i] << " ";
    cout << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3684kb

input:

5 2
1 2 3 4 5

output:

24 120 60 40 30 

result:

ok 5 number(s): "24 120 60 40 30"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

8 3
12 5 16 14 10 6 9 2

output:

14515200 14515200 14515200 14515200 14515200 14515200 14515200 14515200 

result:

ok 8 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

6 10
3 7 8 2 9 5

output:

56347321 169041963 833775940 811788154 844769833 639990479 

result:

ok 6 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

2 100
1 2

output:

917380677 917380677 

result:

ok 2 number(s): "917380677 917380677"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

1 1
1

output:

1 

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

119 1000000000
179906895 883175111 831258723 617910763 41850684 952649819 667608052 992898634 871657688 261948841 858714230 452797779 698675390 39373823 268148685 762575950 789163136 676908074 134428624 583625412 549545785 415007638 564283552 596519552 575204092 884934270 632550339 21505752 66058955...

output:

375116230 26429781 713091228 558890530 21930790 178825460 670077410 523152589 669414287 97987884 399677029 513881456 107722471 353957452 946672010 508449163 23021836 445766752 334151026 1826665 117696761 694568123 949667235 876304874 367174487 169501255 197879871 462516615 208040656 770105543 958714...

result:

ok 119 numbers

Test #7:

score: 0
Accepted
time: 34ms
memory: 4124kb

input:

60928 1000000000
647034012 758455477 62531806 937429685 597725392 151383361 375173809 62379754 462035375 121434573 370644921 339070881 459180118 524525232 539383343 825690592 862037426 643159998 695754897 799399539 500951305 271294315 721183291 342758823 636098292 891075586 970208329 452034355 24183...

output:

946516222 315310335 562683949 614527727 961228460 778673772 124575531 202861813 358534859 463200249 437273635 356795795 655879659 656235247 146099590 498035900 865525574 430376201 130782952 913561838 202654508 797237275 262113868 612420852 524859489 566612380 301295588 835552939 554799099 203338329 ...

result:

ok 60928 numbers

Test #8:

score: -100
Wrong Answer
time: 56ms
memory: 4800kb

input:

100000 1000000000
984343843 231975068 819209000 195274035 278601046 224249013 804551337 222857445 609670477 952095628 931244133 748912217 393911483 638420373 194474592 489497425 54112292 382356337 859661508 879670192 828408437 52769079 102069187 265385606 611233228 110980823 246539650 225276298 8149...

output:

933026277 478281499 981950526 304613145 323595110 22388925 453872797 333458532 820053609 670964041 649633557 824060055 72821422 412428557 526483568 302129203 303438799 502649111 772856075 459967137 525772522 401868556 422622442 370900002 169918536 205102201 668468121 46936604 287769930 392033575 162...

result:

wrong answer 1st numbers differ - expected: '745607263', found: '933026277'