QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213447#7562. Except OnePHarr#WA 0ms3624kbC++201.3kb2023-10-14 14:16:422023-10-14 14:16:43

Judging History

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

  • [2023-10-14 14:16:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2023-10-14 14:16:42]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long long

using vi = vector<int>;

int p, k, t;

struct matrix {
    int x, y;
    vector<vi> v;

    matrix(int x, int y) : x(x), y(y) {
        v = vector(x + 1, vi(y + 1, 0));
    }

    void I() {
        assert(x == y);
        for (int i = 1; i <= x; i++)
            v[i][i] = 1;
        return;
    }

    friend matrix operator*(const matrix &a, const matrix &b) {
        assert(a.y == b.x);
        matrix ans(a.x, b.y);
        for (int i = 1; i <= a.x; i++)
            for (int j = 1; j <= b.y; j++)
                for (int k = 1; k <= a.y; k++)
                    ans.v[i][j] = (ans.v[i][j] + a.v[i][k] * b.v[k][j] % p) % p;
        return ans;
    }

    friend matrix operator^(matrix x, int y) {
        assert(x.x == x.y);
        matrix ans(x.x, x.y);
        ans.I();
        while (y) {
            if (y & 1) ans = ans * x;
            x = x * x, y >>= 1;
        }
        return ans;
    }
};

int32_t main() {
    cin >> p >> k >> t;

    matrix a(2, 1), b(2, 2);
    a.v[1][1] = p - k, a.v[1][2] = 1;
    b.v[1][1] = -k, b.v[1][2] = p;
    b.v[2][1] = 0, b.v[2][2] = 1;

    auto res = (b ^ ( t - 1 )) * a;
    cout << res.v[1][1] << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

7 5 3

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

11 6 7

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

3 2 1

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

596620183 516846890 38276329

output:

135352707

result:

ok 1 number(s): "135352707"

Test #5:

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

input:

382744931 85302262 235496559

output:

14577469

result:

ok 1 number(s): "14577469"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3620kb

input:

659446013 641119314 378275666

output:

-368821851

result:

wrong answer 1st numbers differ - expected: '290624162', found: '-368821851'