結果

問題 No.435 占い(Extra)
ユーザー pekempeypekempey
提出日時 2016-10-14 23:20:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,805 bytes
コンパイル時間 3,672 ms
コンパイル使用メモリ 163,680 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-17 02:36:47
合計ジャッジ時間 9,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,752 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 1 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 161 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:74:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   74 |                 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);
}

struct CombinationLucas {
	long long p, q;
	long long mod;
	vector<long long> F, invF;

	CombinationLucas(int n, long long p, long long q) : p(p), q(q), F(n), invF(n) {
		mod = 1;
		for (int i = 0; i < q; i++) {
			mod *= p;
		}

		F[0] = 1;
		for (long long i = 1; i < n; i++) {
			if (i % p == 0) {
				F[i] = F[i - 1];
			} else {
				F[i] = F[i - 1] * i % mod;
			}
		}

		invF[n - 1] = modinv(F[n - 1], mod);
		for (long long i = n - 2; i >= 0; i--) {
			if ((i + 1) % p == 0) {
				invF[i] = invF[i + 1];
			} else {
				invF[i] = invF[i + 1] * (i + 1) % mod;
			}
		}
	}

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

	long long operator()(int n, int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		long long result = F[n % (mod * 2)] * invF[(n - r) % (mod * 2)] % mod * invF[r % (mod * 2)] % mod;
		int c = count(n) - count(r) - count(n - r);
		if (c >= 2) return 0;
		if (c == 1) (result *= 3) %= mod;
		return result;
	}
};

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

	CombinationLucas cb(30, 3, 2);

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

		bool zero = true;

		long long ans = 0;
		for (int i = 0; i < n; i++) {
			if (x != 0) zero = false;
			ans += cb(n - 1, i) * (x % 10);
			x = ((x ^ a) + b) % m;
		}
		ans %= 9;
		if (ans == 0) ans = 9;
		if (zero) ans = 0;
		printf("%lld\n", ans);
	}
}
0