結果

問題 No.613 Solitude by the window
ユーザー merom686
提出日時 2017-12-13 01:02:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 876 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 74,092 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-12-14 07:02:07
合計ジャッジ時間 18,589 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other AC * 18 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    int64_t n, m;
    cin >> n >> m;

    int64_t a = min((int64_t)10000, n);

    int64_t k = 2;
    for (int i = 0; i < a; i++) {
        k = k * (k + 4) % m;
    }

    if (n == a) {
        cout << k << endl;
        quick_exit(0);
    }

    int64_t c[1100] = {};
    int64_t l = k, p = 0;
    for (int i = 0;; i++) {
        if (i % (1 << 20) == 0) {
            c[i >> 20] = k;
        }
        k = k * (k + 4) % m;
        if (k == l) {
            p = i + 1;
            break;
        }
    }

    int h = (n - a) % p;
    k = c[h >> 20];
    h %= 1 << 20;
    //cout << h <<' '<<p<< endl;
    for (int i = 0; i < h; i++) {
        k = k * (k + 4) % m;
    }

    cout << k << endl;

    return 0;
}
0