結果
問題 |
No.435 占い(Extra)
|
ユーザー |
![]() |
提出日時 | 2020-04-24 00:36:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 655 ms / 2,000 ms |
コード長 | 1,098 bytes |
コンパイル時間 | 893 ms |
コンパイル使用メモリ | 67,456 KB |
最終ジャッジ日時 | 2025-01-09 22:54:27 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 32 |
ソースコード
#include <iostream> using namespace std; typedef long long ll; int inv[9] = {0, 1, 5, 0, 7, 2, 0, 4, 8}; void solve() { ll n, x, a, b, m, comb, ord; cin >> n >> x >> a >> b >> m; n--; comb = 1; ord = 0; int ret = 0; bool all_zero = true; for (int i = 0; i <= n; i++) { int s = x % 10; all_zero &= (s == 0); if (ord == 0) { ret += comb * s; } else if (ord == 1) { ret += comb * 3 * s; } if (i == n) break; int t = n - i; while (t % 3 == 0) { t /= 3; ord += 1; } comb *= t; comb %= 9; t = i + 1; while (t % 3 == 0) { t /= 3; ord -= 1; } comb *= inv[t % 9]; comb %= 9; x = ((x ^ a) + b) % m; } ret %= 9; if (ret == 0 && !all_zero) { ret = 9; } cout << ret << endl; } int main() { int T; cin >> T; for (int i = 0; i < T; i++) solve(); return 0; }