結果

問題 No.435 占い(Extra)
ユーザー pekempeypekempey
提出日時 2016-10-14 23:48:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,585 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 162,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 02:37:49
合計ジャッジ時間 5,680 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 81 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |                 scanf("%lld %lld %lld %lld %lld", &n, &x, &a, &b, &m);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

pair<long long, long long> extgcd(long long a, long long b) {
	if (b == 0) return{ 1, 0 };
	long long x, y;
	tie(x, y) = extgcd(b, a % b);
	return{ y, x - a / b * y };
}

long long modulo(long long a, long long mod) {
	return (a % mod + mod) % mod;
}

long long modinv(long long a, long long mod) {
	return modulo(extgcd(a, mod).first, mod);
}

int F[100], invF[100];

int count(int n) {
	int res = 0;
	n /= 3;
	while (n > 0) res += n, n /= 3;
	return res;
}

void init() {
	F[0] = 1;
	for (long long i = 1; i < 50; i++) {
		if (i % 3 == 0) {
			F[i] = F[i - 1];
		} else {
			F[i] = F[i - 1] * i % 9;
		}
	}

	invF[49] = modinv(F[49], 9);
	for (long long i = 48; i >= 0; i--) {
		if ((i + 1) % 3 == 0) {
			invF[i] = invF[i + 1];
		} else {
			invF[i] = invF[i + 1] * (i + 1) % 9;
		}
	}
};

int main() {
	int T;
	cin >> T;

	init();

	while (T--) {
		long long n, x, a, b, m;
		scanf("%lld %lld %lld %lld %lld", &n, &x, &a, &b, &m);

		bool zero = true;

		n--;

		int N = count(n);
		int L = 0;
		int R = N;

		long long ans = 0;

		for (int i = 0; i <= n; i++) {
			if (x != 0) zero = false;

			long long comb = F[n % 18] * invF[(n - i) % 18] * invF[i % 18];
			int cnt = N - L - R;
			if (cnt >= 2) comb = 0;
			else if (cnt == 1) comb *= 3;
			(ans += comb * (x % 10)) %= 9;

			if (i < n) {
				for (int t = i + 1; t > 0 && t % 3 == 0; t /= 3) L++;
				for (int t = n - i; t > 0 && t % 3 == 0; t /= 3) R--;
			}

			x = ((x ^ a) + b) % m;
		}
		ans %= 9;
		if (ans == 0) ans = 9;
		if (zero) ans = 0;
		printf("%lld\n", ans);
	}
}
0