QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186225#5661. Multi-LaddersBUET_POTATOES#AC ✓0ms3572kbC++20948b2023-09-23 13:50:192023-09-23 13:50:20

Judging History

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

  • [2023-09-23 13:50:20]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3572kb
  • [2023-09-23 13:50:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

long long binpow(long long a, long long b, long long m = mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll modinv(ll a){
    return binpow(a, mod-2);
}

void solv(int ces){
    ll n,k,x;
    cin>>n>>k>>x;
    if(x<=2){
        cout<<"0\n";
    }
    else{
        ll ans = binpow(x*x-3*x+3, (n-1)*k);
        ans = (ans * binpow(x-1, k-1)) % mod;
        ll Y = (1-x + mod) % mod;
        ll Z = (modinv(binpow(Y, k-2)) + x-1) % mod;
        ans = (ans * Z) % mod;
        cout<<ans<<"\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);


    int tc = 1;
    cin>>tc;
    for(int ces=1; ces<=tc; ces++){
        solv(ces);
    }

    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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