結果
問題 | No.613 Solitude by the window |
ユーザー |
|
提出日時 | 2017-12-13 00:12:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 936 bytes |
コンパイル時間 | 541 ms |
コンパイル使用メモリ | 51,968 KB |
最終ジャッジ日時 | 2025-01-05 05:10:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 10 RE * 2 TLE * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%lld%lld", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~~~~~ main.cpp:44:16: warning: ‘extra’ may be used uninitialized [-Wmaybe-uninitialized] 44 | n %= (target - extra); | ~~~~~~~~^~~~~~~~ main.cpp:21:20: note: ‘extra’ was declared here 21 | int64 x = 2 % m, extra, target = -1, end; | ^~~~~
ソースコード
#include <cstdio> #include <vector> #include <map> using int64 = long long; int main() { int64 n, m; scanf("%lld%lld", &n, &m); if (m == 1000000007) { n %= 250000001; int64 x = 2; for (int i = 0; i < n; ++i) { x = (x * x + 4 * x) % m; } printf("%lld\n", x); return 0; } std::vector<bool> mark(m); mark[2 % m] = 1; int64 x = 2 % m, extra, target = -1, end; for (int i = 1; i <= n; ++i) { x = (x * x + 4 * x) % m; if (mark[x]) { target = x; end = i; break; } mark[x] = 1; } if (target == -1) { printf("%lld\n", x); return 0; } x = 2 % m; for (int i = 0; i <= n; ++i) { if (x == target) { extra = i; break; } x = (x * x + 4 * x) % m; } n -= extra; n %= (target - extra); if (n == 0) n += (target - extra); for (int i = 0; i < n; ++i) { x = (x * x + x * 4) % m; } printf("%lld\n", x); return 0; }