QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#139199#5661. Multi-Laddershano#AC ✓1ms3472kbC++141.8kb2023-08-12 19:38:472023-08-12 19:38:48

Judging History

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

  • [2023-08-12 19:38:48]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3472kb
  • [2023-08-12 19:38:47]
  • 提交

answer

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

ll sq(ll x){
	return (x*x)%mod;
}
ll bin(ll a,ll b){
	if(b==0)return 1;
	if(b&1){
		return (a*sq(bin(a,b>>1)))%mod;
	}
	return sq(bin(a,b>>1))%mod;
}
struct mat{
	int nn,mm;
	ll a[2][2];
	void init(){
		memset(a,0,sizeof a);
	}
	mat mul(mat b){
		mat res;
		res.init();
		res.nn=nn,res.mm=mm;
		for(int i=0;i<nn;i++){
			for(int j=0;j<mm;j++){
				for(int k=0;k<nn;k++){
					res.a[i][j]+=a[i][k]*b.a[k][j];
					res.a[i][j]%=mod;
				}
			}
		}
		return res;
	}
};

mat sqm(mat x){
	return x.mul(x);
}
mat binm(mat a,ll b){
	if(b==0){
		mat id;
		id.init();
		id.nn=2,id.mm=2;
		id.a[0][0]=1,id.a[1][1]=1;
		return id;
	}
	if(b&1){
		return a.mul(sqm(binm(a,b>>1)));
	}
	return sqm(binm(a,b>>1));
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int t;
	cin>>t;
	while(t--){
		ll n,k,l;cin>>n>>k>>l;
		if(k%2 && l==2){	
			cout<<0<<endl;
			continue;
		}
		if(l<2){
			cout<<0<<endl;
			continue;
		}
		ll ans=0;
		/*
		ll ans=l*(l-2);
		ans%=mod;
		ans*=bin(l-1,k-2);
		ans%=mod;
		if(k!=3)ans+=(l*bin(l-1,k-1))%mod,ans%=mod;
		*/
		ll base=l*(l-1);
		base%=mod;
		base*=(l-2);
		base%=mod;
		mat a;
		a.init();
		a.nn=2,a.mm=2;
		a.a[0][0]=0,a.a[0][1]=1,a.a[1][0]=l-1,a.a[1][1]=l-2;
		mat res=binm(a,k-3);
		/*for(int i=1;i<2;i++){
			for(int j=0;j<2;j++){
				ans+=res.a[1][j]*base;
				ans%=mod;
			}
		}
		*/
		ll bs=l*(l-1);
		bs%=mod;
		ans+=res.a[1][0]*bs;
		ans%=mod;
		ans+=res.a[1][1]*base;
		ans%=mod;
		if(l==2){
			ans=2;
		}
		if(n==1){
			cout<<ans<<endl;
			continue;
		}
		ll hnhn=(l-2)*(l-3);
		hnhn%=mod;
		hnhn+=(l-1)*2-1;
		hnhn%=mod;
		hnhn=bin(hnhn,n-1);
		hnhn%=mod;
		ans*=bin(hnhn,k);
		ans%=mod;
		cout<<ans<<endl;
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3380kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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