結果
| 問題 | No.435 占い(Extra) |
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2026-06-14 12:49:47 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 116 ms / 2,000 ms |
| コード長 | 2,105 bytes |
| 記録 | |
| コンパイル時間 | 2,358 ms |
| コンパイル使用メモリ | 331,584 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-14 12:49:52 |
| 合計ジャッジ時間 | 5,075 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 |
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
// using namespace atcoder;
// using mint = modint1000000007;
// const int mod = 1000000007;
// using mint = modint998244353;
// const int mod = 998244353;
// const int INF = 1e9;
// const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, l, r) for (int i = (l); i < (r); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, l, r) for (int i = (r)-1; i >= (l); --i)
#define all(x) (x).begin(), (x).end()
#define allR(x) (x).rbegin(), (x).rend()
#define P pair<int, int>
template<typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return true; } return false; }
static inline int inv_mod9(int x) {
switch (x % 9) {
case 1: return 1;
case 2: return 5;
case 4: return 7;
case 5: return 2;
case 7: return 4;
case 8: return 8;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int n;
long long x, a, b, m;
cin >> n >> x >> a >> b >> m;
int N = n - 1;
long long r = x;
int ans = 0;
// C(N,0)=1
int unit = 1; // 3 を除いた部分 mod 9
int e = 0; // 3 の指数
bool non_zero_digit = false;
rep(i, n) {
if (i) {
r = ((r ^ a) + b) % m;
}
// cout << r << endl;
int d = r % 10;
if (d) non_zero_digit = true;
int coef;
if (e >= 2) {
coef = 0;
}
else if (e == 1) {
coef = unit * 3 % 9;
}
else {
coef = unit;
}
ans += coef * (int)(r % 10);
ans %= 9;
if (i == N) continue;
long long num = N - i;
long long den = i + 1;
int cnum = 0;
while (num % 3 == 0) {
num /= 3;
cnum++;
}
int cden = 0;
while (den % 3 == 0) {
den /= 3;
cden++;
}
e += cnum - cden;
unit = unit * (int)(num % 9) % 9;
unit = unit * inv_mod9((int)(den % 9)) % 9;
}
if (ans == 0 && non_zero_digit) ans = 9;
cout << ans << '\n';
}
return 0;
}
kwm_t