結果
問題 | No.2122 黄金比で擬似乱数生成 |
ユーザー |
![]() |
提出日時 | 2022-11-04 23:27:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,123 bytes |
コンパイル時間 | 2,933 ms |
コンパイル使用メモリ | 252,700 KB |
最終ジャッジ日時 | 2025-02-08 18:21:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
#include <bits/extc++.h> int main() { using namespace std; constexpr unsigned long mod{10000}; unsigned long S{}, M, L; { string s; cin >> s; for(const auto c : s)(S *= 10) += c - 48; } cin >> M >> L; const auto m_shuffle{[&M](unsigned long x){ unsigned long a{}, b{1}, c{x}, d{1}, e{}, f{1}; unsigned long n{M}; while(n){ if(n & 1){ tie(d, e, f) = make_tuple(a * d + b * e, b * d + c * e, b * e + c * f); tie(d, e, f) = make_tuple(d % mod, e % mod, f % mod); } tie(a, b, c) = make_tuple(a * a + b * b, b * (a + c), b * b + c * c); tie(a, b, c) = make_tuple(a % mod, b % mod, c % mod); n /= 2; } if(M & 1)(e += 9999) %= mod; return e; }}; vector<optional<unsigned long>> num(10000); for(unsigned long i{}; i < L; ++i){ if(num[S]){ const auto C{i - num[S].value()}; i += (L - i) / C * C; }else num[S] = i; S = m_shuffle(S); } printf("%04lu\n", S); return 0; }