QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#320647 | #5661. Multi-Ladders | ushg8877 | AC ✓ | 0ms | 3828kb | C++20 | 830b | 2024-02-03 19:25:48 | 2024-02-03 19:25:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MP make_pair
mt19937 rnd(time(0));
const int MOD=1e9+7;
ll n,k,c;
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a%MOD;a=a*a%MOD,b>>=1;}return r;}
struct matrix{
ll a[2][2];
matrix(){memset(a,0,sizeof(a));}
};
matrix operator *(matrix A,matrix B){
matrix C;
for(int i:{0,1}) for(int j:{0,1}) for(int k:{0,1}){
C.a[i][j]+=A.a[i][k]*B.a[k][j];
C.a[i][j]%=MOD;
}
return C;
}
void solve(){
cin>>k>>n>>c;
matrix A,B;
A.a[0][0]=1;
B.a[0][0]=0;B.a[0][1]=1;
B.a[1][0]=c-1;B.a[1][1]=c-2;
for(int i=0;i<=62;i++){
if((n-1)>>i&1) A=A*B;
B=B*B;
}
cout<<c*(c-1)%MOD*A.a[0][1]%MOD*ksm(((c-1)*(c-1)-(c-2))%MOD,n*(k-1))%MOD<<endl;
}
int main(){
ios::sync_with_stdio(false);
int _;cin>>_;
while(_--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
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