結果

問題 No.613 Solitude by the window
ユーザー uenokuuenoku
提出日時 2017-12-13 05:23:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,036 bytes
コンパイル時間 1,411 ms
コンパイル使用メモリ 164,992 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-21 00:50:07
合計ジャッジ時間 5,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,476 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
bool used[1100000001] = {};
int main()
{
    lli n, m;
    cin >> n >> m;
    lli v = 2;
    used[v] = true;
    n--;
    rep(i, m)
    {
        v = (v * (v + 4)) % m;
        if (i == n) {
            cout << v << endl;
            return 0;
        }
        if (used[v]) {
            lli vv = 2;
            rep(k, m)
            {
                if (vv == v) {
                    //                    cout << i << " " << k << endl;
                    lli p = (i + 1 - k);
                    lli ret = (n - k) % p;
                    rep(j, ret + 1)
                    {
                        vv = vv * (vv + 4);
                        vv %= m;
                    }
                    cout << vv << endl;
                    return 0;
                }
                vv = vv * (vv + 4);
                vv %= m;
            }
        }
    }
}
0