結果

問題 No.434 占い
ユーザー square1001square1001
提出日時 2018-05-20 20:36:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 822 bytes
コンパイル時間 2,833 ms
コンパイル使用メモリ 32,436 KB
実行使用メモリ 26,776 KB
最終ジャッジ日時 2023-09-11 00:08:29
合計ジャッジ時間 5,196 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#pragma warning(disable : 4996)
const int inv[] = { 0, 1, 5, 0, 7, 2, 0, 4, 8 };
int q, n, x, a, b, m; short fact[10000009];
int main() {
	fact[0] = 1;
	for (int i = 1; i <= 10000000; ++i) {
		x = i;
		while (x % 3 == 0) x /= 3;
		fact[i] = fact[i - 1] * x % 9;
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d%d%d%d", &n, &x, &a, &b, &m);
		int cur = x, ord = 0, mul = 1, ret = 0, f = 0;
		for (int i = 0; i < n; i++) {
			if (cur % 10 != 0) f = 1;
			ret = (ret + cur % 10 * (ord == 0 ? mul : (ord == 1 ? mul % 3 * 3 : 0))) % 9;
			cur = ((cur ^ a) + b) % m;
			x = i + 1;
			while (x % 3 == 0) x /= 3, ord--;
			mul = mul * inv[x % 9] % 9;
			x = n - i - 1;
			while (x != 0 && x % 3 == 0) x /= 3, ord++;
			mul = mul * x % 9;
		}
		printf("%d\n", ret + (ret == 0 && f == 1 ? 9 : 0));
	}
	return 0;
}
0