結果

問題 No.1253 雀見椪
ユーザー 👑 KazunKazun
提出日時 2020-08-16 22:36:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 53,768 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 07:10:47
合計ジャッジ時間 2,258 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 68 ms
4,376 KB
testcase_05 AC 69 ms
4,376 KB
testcase_06 AC 68 ms
4,380 KB
testcase_07 AC 69 ms
4,380 KB
testcase_08 AC 68 ms
4,376 KB
testcase_09 AC 69 ms
4,376 KB
testcase_10 AC 68 ms
4,376 KB
testcase_11 AC 69 ms
4,376 KB
testcase_12 AC 69 ms
4,376 KB
testcase_13 AC 68 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

long long  power_mod(long long a, long long p, long long m) {
	long long ans = 1;
	long long x = a;

	while (p>0) {
		if (p % 2 == 1) {
			ans = (ans * x) % m;
		}
		p /= 2;
		x = (x * x) % m;
	}
	return ans;
}

int main() {
	long long T;
	long long N,a, b, c, p, q, r;
	long long M = 1000000007;
	long long x, y, z;
	long long J, K;

	cin >> T;
	for (int i = 0; i < T; i++) {
		cin >> N >> a >> p >> b >> q >> c >> r;

		x = (a * power_mod(p, M - 2, M)) % M;
		y = (b * power_mod(q, M - 2, M)) % M;
		z = (c * power_mod(r, M - 2, M)) % M;

		J = (power_mod(1 - x, N, M) + power_mod(1 - y, N, M) + power_mod(1 - z, N, M)) % M;
		K = (power_mod(x, N, M) + power_mod(y, N, M) + power_mod(z, N, M)) % M;
		cout << ((1 - J + 2 * K)+M) % M << endl;
	}
	return 0;
}

0