QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184053#5661. Multi-Laddersucup-team1209#AC ✓1ms3520kbC++201.6kb2023-09-20 11:03:572023-09-20 11:03:58

Judging History

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

  • [2023-09-20 11:03:58]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3520kb
  • [2023-09-20 11:03:57]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

using ll = long long ; 

cs int mod = 1e9 + 7;
void add(int &x ,int y) {
    if((x += y) >= mod) x -= mod; 
}
void dec(int &x, int y) {
    if((x -= y) < 0) x += mod; 
}
int mul(int &x, int y) {
    return 1ll * x * y % mod; 
}
int ksm(int a, int b) {
    int c = 1; 
    for(; b; b >>= 1, a = mul(a, a)) 
    if(b & 1) c = mul(c, a);
    return c; 
}
cs int N = 205; 
int T, n, k, a; 

struct mat {
    int a[2][2];
    mat() {
        memset(a, 0, sizeof a);
    }
    mat operator * (cs mat & x) {
        mat y; 
        for(int i = 0; i < 2; i++)
        for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++)
        add(y.a[i][j], mul(a[i][k], x.a[k][j]));
        return y; 
    }
}; 

mat pow(mat a, int b) {
    mat c; 
    c.a[0][0] = c.a[1][1] = 1; 
    for(; b; b >>= 1, a = a * a)
    if(b & 1) c = c * a;
    return c; 
}

void Main() {
    cin >> n >> k >> a;
    if(a < 2) {
        cout << 0 << '\n';
        return; 
    }
    ll cc = 1ll * a * a - 3ll * a + 3ll; 
    cc = cc % mod; 
    int ww = ksm(cc, 1ll * k * (n - 1) % (mod - 1));
    mat r; 
    // cout << ww << endl;
    r.a[0][0] = a - 2; 
    r.a[0][1] = 1; 
    r.a[1][0] = a - 1; 
    r = pow(r, k - 1); 
    // cout << r.a[0][0] << ' ' << r.a[0][1] << ' ' << r.a[1][0] << ' ' << r.a[1][1] << endl;
    ww = mul(ww, mul(r.a[1][0], a));
    cout << ww << '\n';
}

int main() {
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    cin >> T; 
    while(T--) Main();
    return 0; 
}

詳細信息

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3520kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
6
0
0
0
0
349400141
243010659
52489881
53690844
176686901
218103365
558243892
991895211
693053429
883715672
80402569
0
0
311752813

result:

ok 20 lines