結果
| 問題 | No.1253 雀見椪 | 
| コンテスト | |
| ユーザー |  Nachia | 
| 提出日時 | 2020-10-09 21:40:38 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,061 ms / 2,000 ms | 
| コード長 | 1,289 bytes | 
| コンパイル時間 | 1,593 ms | 
| コンパイル使用メモリ | 168,460 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-20 10:00:42 | 
| 合計ジャッジ時間 | 13,012 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 14 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const ULL M = 1000000007;
ULL powm(ULL a, ULL i) {
	if (i == 0) return 1;
	ULL ans = powm(a * a % M, i / 2);
	if (i & 1) ans = ans * a % M;
	return ans;
}
ULL invm(ULL a) { return powm(a, M - 2); }
struct Matrix {
	ULL A[8][8] = {};
};
Matrix MatrixId() {
	Matrix ans;
	rep(i, 8) ans.A[i][i] = 1;
	return ans;
}
Matrix operator*(Matrix a, Matrix b) {
	Matrix ans;
	rep(i, 8) rep(j, 8) rep(k, 8) ans.A[i][j] = (ans.A[i][j] + a.A[i][k] * b.A[k][j]) % M;
	return ans;
}
Matrix operator^(Matrix a, ULL i) {
	if (i == 0) return MatrixId();
	Matrix ans =(a * a) ^ (i / 2);
	if (i & 1) ans = ans * a;
	return ans;
}
Matrix Janken(ULL goo, ULL choki, ULL pah) {
	Matrix ans;
	rep(i, 8) {
		ans.A[i][i | 1] = (ans.A[i][i | 1] + goo) % M;
		ans.A[i][i | 2] = (ans.A[i][i | 2] + choki) % M;
		ans.A[i][i | 4] = (ans.A[i][i | 4] + pah) % M;;
	}
	return ans;
}
int main() {
	int T; cin >> T;
	while (T--) {
		ULL N; cin >> N;
		ULL P[3];
		rep(i, 3) { ULL a, b; cin >> a >> b; P[i] = a * invm(b) % M; }
		Matrix X = Janken(P[0], P[1], P[2]) ^ N;
		ULL ans = X.A[0][1] + X.A[0][2] + X.A[0][4] + X.A[0][7];
		ans %= M;
		cout << ans << endl;
	}
	return 0;
}
            
            
            
        