QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186051#5661. Multi-Laddersaesthetic#AC ✓0ms3632kbC++202.1kb2023-09-23 03:02:452023-09-23 03:02:46

Judging History

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

  • [2023-09-23 03:02:46]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3632kb
  • [2023-09-23 03:02:45]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
long long n, k, lam;

long long gbrute(int x)
{
    if(x == 1)
        return 0;
    if(x == 2)    
        return lam * (lam - 1) % MOD;
    return (gbrute(x - 1)* (lam - 2) % MOD + gbrute(x - 2) * (lam - 1) % MOD) % MOD;
}

struct mat
{
    long long elem[2][2];
    mat operator *(const mat &o) const
    {
        mat ret;
        for(int i = 0; i < 2; ++i)
            for(int j = 0; j < 2; ++j)
            {
                long long acc = 0;
                for(int k = 0; k < 2; ++k)
                    acc += elem[i][k] * o.elem[k][j] % MOD;
                ret.elem[i][j] = acc % MOD;
            }
        return ret;
    }

    static mat identity()
    {
        mat m;
        m.elem[0][0] = 1;
        m.elem[0][1] = 0;
        m.elem[1][0] = 0;
        m.elem[1][1] = 1;
        return m;
    }
};

mat powmat(mat &m, long long e)
{
    if(!e)
        return mat::identity();
    if(e & 1)
        return m * powmat(m, e - 1);
    mat aux = powmat(m, e >> 1);
    return aux * aux;
}

long long g(long long x)
{
    mat m;
    m.elem[0][0] = lam - 2;
    m.elem[0][1] = lam - 1;
    m.elem[1][0] = 1;
    m.elem[1][1] = 0;

    m = powmat(m, x - 1);

    return m.elem[1][0] * (lam - 1) % MOD * lam % MOD;
}

long long powm(long long b, long long e, long long m)
{
    if(!e)
        return 1;
    if(e & 1)
        return b * powm(b, e - 1, m) % m;
    long long aux = powm(b, e >> 1, m);
    return aux * aux % m;
}

void solve()
{
    cin >> n >> k >> lam;
    if(lam == 0){
        cout<<"0\n";
        return;
    }

    long long a = ((lam - 1) + (lam - 2) * (lam - 2) % MOD) % MOD;
    long long ans = g(k);
    long long aa = powm(a, k, MOD);
    aa = powm(aa, n - 1, MOD);
    cout << (ans * aa) % MOD << '\n';
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); 
    #endif
    ios_base::sync_with_stdio(false), cin.tie(NULL);

    int t;
    for(cin >> t; t--;)
    {
        solve();
    }   
}

詳細信息

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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