QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94858#5661. Multi-Ladderspedroteosousa#AC ✓2ms3752kbC++141.2kb2023-04-08 00:41:322023-04-08 00:41:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-08 00:41:34]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3752kb
  • [2023-04-08 00:41:32]
  • 提交

answer

#include <bits/stdc++.h>
#define mod 1'000'000'007
#define ll long long
using namespace std;

int v[100100];

struct mat {

	ll M[2][2];

	mat operator*(mat a){
		
		mat ret;
		
		for(int i=0;i<2;i++)
			for(int j=0;j<2;j++){
				ret.M[i][j] = 0;
				for(int k=0;k<2;k++)
					ret.M[i][j] += M[i][k] * a.M[k][j];
				ret.M[i][j] %= mod;
			}
			
		return ret;
		
	}
	
};

mat id;

mat exp(mat A,ll k){
	if(k == 0) return id;
	mat aux = exp(A,k/2);
	aux = aux * aux;
	if(k%2 == 1)
		aux = aux * A;
	return aux;
}

ll exp(ll a,ll b){
	if(b == 0) return 1;
	ll k = exp(a,b/2);
	k = (k*k) % mod;
	if(b%2 == 1)
		k = (k*a) % mod;
	return k;
}
		

main(){

	int nt;
	scanf("%d",&nt);
	
	while(nt--){
	
		ll n,k,lam;
		scanf("%lld%lld%lld",&n,&k,&lam);
		
		id.M[0][0] = id.M[1][1] = 1;
		
		mat A;
		
		A.M[0][0] = 0;
		A.M[1][0] = 1;
		A.M[0][1] = lam-1;
		A.M[1][1] = lam-2;
		
		A = exp(A,k-1);
		
		ll D = A.M[0][1];
		
		D *= lam;
		D %= mod;
		
		ll line = ( (lam-1)*(lam-1) - (lam-2)) % mod;
		ll qtd_lines = ( k * (n-1)) % (mod-1);
		
		ll borda = exp(line,qtd_lines);
		
		ll ans = (D * borda) % mod;
		
		printf("%lld\n",ans);
		
	}

}
		
		

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3508kb

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