QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#524991#5021. 六元不定方程Rong7100 ✓1ms4144kbC++144.4kb2024-08-20 11:28:392024-08-20 11:28:40

Judging History

This is the latest submission verdict.

  • [2024-08-20 11:28:40]
  • Judged
  • Verdict: 100
  • Time: 1ms
  • Memory: 4144kb
  • [2024-08-20 11:28:39]
  • Submitted

answer

// Go in my style.
// Not afraid to dark.

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

clock_t start_time, end_time;
#define GET_START start_time = clock ();
#define GET_END end_time = clock (); fprintf (stderr, "TIME COSSEMED : %0.3lf\n", 1.0 * (end_time - start_time) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

#define int long long
#define i128 __int128

namespace io {
    int read_pos, read_dt; char read_char;
    inline int read (int &p = read_pos){
        p = 0, read_dt = 1; read_char = getchar ();
        while (! isdigit (read_char)){
            if (read_char == '-')
                read_dt = - 1;
            read_char = getchar ();
        }
        while (isdigit (read_char)){
            p = (p << 1) + (p << 3) + read_char - 48;
            read_char = getchar ();
        }
        return p = p * read_dt;
    }
    int write_sta[65], write_top;
    inline void write (int x){
        if (x < 0)
            putchar ('-'), x = - x;
        write_top = 0;
        do
            write_sta[write_top ++] = x % 10, x /= 10;
        while (x);
        while (write_top)
            putchar (write_sta[-- write_top] + 48);
    }
}

int n, r;

namespace NUMBER {

    mt19937_64 mtrand (time (0));

    inline int power (int a, int p, int mod){
        int res = 1;
        while (p > 0){
            if (p & 1)
                res = (i128) res * a % mod;
            a = (i128) a * a % mod;
            p >>= 1;
        }
        return res;
    }
    int gcd (int i, int j){
        if (j == 0)
            return i;
        return gcd (j, i % j);
    }
    #define log2_(x) (63 ^ __builtin_clzll (x))

    int ae[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    inline bool MR (int p){
        if (p < 2)
            return false;
        if (p < 4)
            return true;
        static int d, r; d = p - 1, r = 0;
        while (! (d & 1))
            d >>= 1, ++ r;
        for (int i = 0, a, x, T;i < 7;++ i){
            a = ae[i] % p;
            if (a == 1 || a == p - 1 || a == 0)
                continue;
            x = power (a, d, p);
            if (x == 1)
                continue;
            for (T = r;T --;){
                if (x == p - 1)
                    break;
                x = (i128) x * x % p;
            }
            if (T < 0)
                return false;
        }
        return true;
    }
    inline int PR (int p){
        static int s, t, c, i, ed, prd, d;
        s = t = 0, c = mtrand () % (p - 1) + 1;
        for (ed = 1;;ed <<= 1){
            prd = 1, s = t;
            for (i = 1;i <= ed;++ i){
                t = ((i128) t * t + c) % p;
                prd = (i128) prd * abs (t - s) % p;
                if (i % 127 == 0){
                    d = gcd (prd, p);
                    if (d > 1)
                        return d;
                }
            }
            d = gcd (prd, p);
            if (d > 1)
                return d;
        }
        return - 1;
    }
    void FAC (int p, vector < int > &fac, int t = 1){
        if (p < 2)
            return ;
        if (MR (p)){
            while (t --)
                fac.push_back (p);
            return ;
        }
        int x;
        do
            x = PR (p);
        while (x >= p);
        int r = 0;
        while (p % x == 0)
            p /= x, ++ r;
        FAC (p, fac, t), FAC (x, fac, t * r);
    }
} using namespace NUMBER;

const int mod = 998244353;

#define sgn(x) ((x) & 1 ? - 1 : 1)

inline int Solve (int p){
    static int C, res, pp, C0; pp = p % mod;
    C0 = ((pp - 1) * sgn (p - 1 >> 1) % mod + pp) % mod;
    C0 = (C0 + mod) % mod;
    if (p == 2) C = C0 = 2;
    else if (r % p == 0) C = C0;
    else C = (pp - sgn (p - 1 >> 1)) % mod, C = (C + mod) % mod;
    if (r % p == 0){
        res = (C - 1) * (pp - 1) % mod * (pp - 1) % mod;
        res = (res + 3ll * pp % mod * pp % mod * pp % mod - 3ll * pp % mod + 1) % mod;
    } else {
        res = C * pp % mod;
        res = (res + (pp * pp % mod - 1) * pp % mod - (pp * pp % mod - C0) % mod) % mod;
    }
    res = (res + mod) % mod;
    return res;
}

signed main (){
    GET_START

    io::read (n), io::read (r);
    int ans = 1;
    vector < int > fac; FAC (n, fac);
    for (int p : fac)
        ans = ans * Solve (p) % mod;
    io::write (ans), putchar ('\n');

    GET_END
    return 0;
}

详细

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 0ms
memory: 4036kb

input:

47 2

output:

103824

result:

ok answer is 103824

Test #2:

score: 7
Accepted
time: 0ms
memory: 3916kb

input:

42 6

output:

502240

result:

ok answer is 502240

Test #3:

score: 7
Accepted
time: 0ms
memory: 3968kb

input:

42 7

output:

226016

result:

ok answer is 226016

Test #4:

score: 7
Accepted
time: 0ms
memory: 4140kb

input:

35 1

output:

42656

result:

ok answer is 42656

Test #5:

score: 7
Accepted
time: 0ms
memory: 4136kb

input:

30 4

output:

69440

result:

ok answer is 69440

Subtask #2:

score: 8
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 8
Accepted
time: 0ms
memory: 3928kb

input:

499 333

output:

124251500

result:

ok answer is 124251500

Test #7:

score: 8
Accepted
time: 0ms
memory: 3992kb

input:

498 22

output:

320201280

result:

ok answer is 320201280

Test #8:

score: 8
Accepted
time: 0ms
memory: 3928kb

input:

498 83

output:

384185312

result:

ok answer is 384185312

Test #9:

score: 8
Accepted
time: 0ms
memory: 3920kb

input:

390 20

output:

601352640

result:

ok answer is 601352640

Test #10:

score: 8
Accepted
time: 0ms
memory: 4128kb

input:

345 46

output:

126495376

result:

ok answer is 126495376

Test #11:

score: 8
Accepted
time: 0ms
memory: 3844kb

input:

286 1

output:

23400576

result:

ok answer is 23400576

Test #12:

score: 8
Accepted
time: 0ms
memory: 3988kb

input:

210 0

output:

720365460

result:

ok answer is 720365460

Subtask #3:

score: 15
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 15
Accepted
time: 0ms
memory: 4064kb

input:

9982687 1

output:

833369372

result:

ok answer is 833369372

Test #14:

score: 15
Accepted
time: 0ms
memory: 3732kb

input:

9665265 22219

output:

780386669

result:

ok answer is 780386669

Test #15:

score: 15
Accepted
time: 0ms
memory: 3732kb

input:

9649078 0

output:

510067513

result:

ok answer is 510067513

Test #16:

score: 15
Accepted
time: 0ms
memory: 4136kb

input:

9423655 12345

output:

198251909

result:

ok answer is 198251909

Test #17:

score: 15
Accepted
time: 0ms
memory: 3840kb

input:

9024847 54041

output:

414888066

result:

ok answer is 414888066

Test #18:

score: 15
Accepted
time: 0ms
memory: 3916kb

input:

8687543 23291

output:

738656105

result:

ok answer is 738656105

Test #19:

score: 15
Accepted
time: 0ms
memory: 4136kb

input:

8620018 297242

output:

983378133

result:

ok answer is 983378133

Test #20:

score: 15
Accepted
time: 0ms
memory: 3988kb

input:

8588469 1451

output:

951537138

result:

ok answer is 951537138

Test #21:

score: 15
Accepted
time: 0ms
memory: 3732kb

input:

8433805 5

output:

567636668

result:

ok answer is 567636668

Test #22:

score: 15
Accepted
time: 0ms
memory: 4128kb

input:

8314621 0

output:

79369486

result:

ok answer is 79369486

Subtask #4:

score: 20
Accepted

Test #23:

score: 20
Accepted
time: 0ms
memory: 3916kb

input:

9988070794 0

output:

892817552

result:

ok answer is 892817552

Test #24:

score: 20
Accepted
time: 0ms
memory: 3844kb

input:

9972429418 0

output:

719993084

result:

ok answer is 719993084

Test #25:

score: 20
Accepted
time: 0ms
memory: 3968kb

input:

9966431717 0

output:

966286891

result:

ok answer is 966286891

Test #26:

score: 20
Accepted
time: 0ms
memory: 3840kb

input:

9966178102 0

output:

116743504

result:

ok answer is 116743504

Test #27:

score: 20
Accepted
time: 0ms
memory: 3804kb

input:

9951622123 0

output:

419542959

result:

ok answer is 419542959

Test #28:

score: 20
Accepted
time: 0ms
memory: 3968kb

input:

9937736483 0

output:

84680671

result:

ok answer is 84680671

Test #29:

score: 20
Accepted
time: 0ms
memory: 3964kb

input:

9928468003 0

output:

548567043

result:

ok answer is 548567043

Test #30:

score: 20
Accepted
time: 0ms
memory: 3844kb

input:

9901819126 0

output:

262055683

result:

ok answer is 262055683

Test #31:

score: 20
Accepted
time: 0ms
memory: 3844kb

input:

9873091542 0

output:

877294745

result:

ok answer is 877294745

Test #32:

score: 20
Accepted
time: 0ms
memory: 3972kb

input:

9853543022 0

output:

739903570

result:

ok answer is 739903570

Subtask #5:

score: 20
Accepted

Test #33:

score: 20
Accepted
time: 0ms
memory: 3924kb

input:

9969724230 1

output:

527859436

result:

ok answer is 527859436

Test #34:

score: 20
Accepted
time: 0ms
memory: 4140kb

input:

9964838918 1

output:

969835202

result:

ok answer is 969835202

Test #35:

score: 20
Accepted
time: 0ms
memory: 4136kb

input:

9911664446 1

output:

951283512

result:

ok answer is 951283512

Test #36:

score: 20
Accepted
time: 0ms
memory: 4032kb

input:

9882518010 1

output:

8204420

result:

ok answer is 8204420

Test #37:

score: 20
Accepted
time: 0ms
memory: 4064kb

input:

9852510959 1

output:

255096514

result:

ok answer is 255096514

Test #38:

score: 20
Accepted
time: 0ms
memory: 3996kb

input:

9849266182 1

output:

217274142

result:

ok answer is 217274142

Test #39:

score: 20
Accepted
time: 0ms
memory: 3736kb

input:

9791892338 1

output:

325668125

result:

ok answer is 325668125

Test #40:

score: 20
Accepted
time: 0ms
memory: 3804kb

input:

9788777311 1

output:

263084896

result:

ok answer is 263084896

Test #41:

score: 20
Accepted
time: 0ms
memory: 4144kb

input:

9770828129 1

output:

334761590

result:

ok answer is 334761590

Test #42:

score: 20
Accepted
time: 0ms
memory: 3924kb

input:

9766387838 1

output:

894928242

result:

ok answer is 894928242

Subtask #6:

score: 10
Accepted

Test #43:

score: 10
Accepted
time: 0ms
memory: 3924kb

input:

970453956888041837 0

output:

645066299

result:

ok answer is 645066299

Test #44:

score: 10
Accepted
time: 1ms
memory: 3920kb

input:

931194651310010123 171424099

output:

509436117

result:

ok answer is 509436117

Test #45:

score: 10
Accepted
time: 0ms
memory: 3776kb

input:

907038108223508551 0

output:

165963545

result:

ok answer is 165963545

Test #46:

score: 10
Accepted
time: 0ms
memory: 4136kb

input:

872894846856586517 0

output:

16659004

result:

ok answer is 16659004

Test #47:

score: 10
Accepted
time: 0ms
memory: 3844kb

input:

824587281708021301 0

output:

196823133

result:

ok answer is 196823133

Test #48:

score: 10
Accepted
time: 0ms
memory: 3924kb

input:

757939300287057419 4081004373

output:

561901817

result:

ok answer is 561901817

Test #49:

score: 10
Accepted
time: 0ms
memory: 3728kb

input:

705849997001114851 3871857366

output:

650365127

result:

ok answer is 650365127

Test #50:

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

input:

652610414906722897 0

output:

440955612

result:

ok answer is 440955612

Test #51:

score: 10
Accepted
time: 0ms
memory: 4020kb

input:

646175904545988703 0

output:

522822575

result:

ok answer is 522822575

Test #52:

score: 10
Accepted
time: 0ms
memory: 3968kb

input:

590437758476363971 3750950939

output:

128252968

result:

ok answer is 128252968

Subtask #7:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #53:

score: 20
Accepted
time: 0ms
memory: 3800kb

input:

947005028140256067 3

output:

685724558

result:

ok answer is 685724558

Test #54:

score: 20
Accepted
time: 0ms
memory: 3732kb

input:

650562918533485234 0

output:

969128068

result:

ok answer is 969128068

Test #55:

score: 20
Accepted
time: 0ms
memory: 3972kb

input:

810331430612257297 7434233308369333

output:

286670205

result:

ok answer is 286670205

Test #56:

score: 20
Accepted
time: 0ms
memory: 3804kb

input:

191130266133495754 26

output:

36044440

result:

ok answer is 36044440

Test #57:

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

input:

256972175102435909 0

output:

163076455

result:

ok answer is 163076455

Test #58:

score: 20
Accepted
time: 0ms
memory: 3996kb

input:

922821875283979361 6735926096963353

output:

132162975

result:

ok answer is 132162975

Test #59:

score: 20
Accepted
time: 0ms
memory: 3996kb

input:

336443768560106918 1

output:

355145101

result:

ok answer is 355145101

Test #60:

score: 20
Accepted
time: 0ms
memory: 4064kb

input:

521622354091666449 173874118030555483

output:

602419902

result:

ok answer is 602419902

Test #61:

score: 20
Accepted
time: 0ms
memory: 4016kb

input:

161587891045624501 0

output:

4096284

result:

ok answer is 4096284

Test #62:

score: 20
Accepted
time: 0ms
memory: 3924kb

input:

918015756417754473 177

output:

898506288

result:

ok answer is 898506288

Test #63:

score: 20
Accepted
time: 0ms
memory: 3916kb

input:

974909818521738877 1

output:

490867530

result:

ok answer is 490867530

Test #64:

score: 20
Accepted
time: 1ms
memory: 3988kb

input:

931353657704809147 0

output:

463150251

result:

ok answer is 463150251

Test #65:

score: 20
Accepted
time: 1ms
memory: 3772kb

input:

877069285688503073 57320337344

output:

272740305

result:

ok answer is 272740305

Test #66:

score: 20
Accepted
time: 0ms
memory: 4012kb

input:

939263795272194911 0

output:

976827347

result:

ok answer is 976827347

Test #67:

score: 20
Accepted
time: 1ms
memory: 4000kb

input:

996421441678288273 1123675667

output:

960318186

result:

ok answer is 960318186

Test #68:

score: 20
Accepted
time: 1ms
memory: 3996kb

input:

981321271852457453 12243967075635

output:

639682371

result:

ok answer is 639682371

Test #69:

score: 20
Accepted
time: 1ms
memory: 3840kb

input:

982370232199372381 990476407

output:

731066550

result:

ok answer is 731066550

Test #70:

score: 20
Accepted
time: 1ms
memory: 3996kb

input:

998045693157780467 109492712669682

output:

976382538

result:

ok answer is 976382538

Test #71:

score: 20
Accepted
time: 1ms
memory: 3928kb

input:

977933905282858861 976891768791

output:

976676969

result:

ok answer is 976676969

Test #72:

score: 20
Accepted
time: 1ms
memory: 3992kb

input:

993920242952842243 0

output:

289796087

result:

ok answer is 289796087