結果

問題 No.613 Solitude by the window
ユーザー pinpin
提出日時 2017-12-13 19:35:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 88,696 KB
実行使用メモリ 103,456 KB
最終ジャッジ日時 2023-08-21 02:20:08
合計ジャッジ時間 27,879 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
11,676 KB
testcase_01 AC 5 ms
11,516 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 170 ms
24,224 KB
testcase_06 AC 402 ms
36,060 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 5 ms
11,660 KB
testcase_18 AC 5 ms
11,508 KB
testcase_19 AC 5 ms
11,564 KB
testcase_20 AC 4 ms
11,588 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

ll n, m;
ll a[2000000];
map<ll, ll> mp;
int main(void){
    cin >> n >> m;
    for (int i = 0; i <= 1000000; i++) a[i] = -1;
    a[0] = (2 * (2 + 4)) % m; mp[a[0]] = 1;
    ll cnt = 1;
    for (int i = 1; i <= 1400000; i++){
        a[i] = (a[i - 1] * (a[i - 1] + 4)) % m;
        if (mp[a[i]] == 1) break;
        mp[a[i]] = 1;
        cnt++;
    }

    if (n%cnt == 0) cout << a[0] << endl;
    else cout << a[n%cnt - 1] << endl;
}
0