結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー trineutrontrineutron
提出日時 2020-10-09 22:48:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 807 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 204,440 KB
実行使用メモリ 15,056 KB
最終ジャッジ日時 2023-09-27 18:47:21
合計ジャッジ時間 7,418 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 449 ms
9,632 KB
testcase_06 AC 687 ms
9,740 KB
testcase_07 AC 479 ms
9,832 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int64_t power(int64_t n, int64_t k, int64_t mod) {
    if (k == 0) return 1;
    int64_t res = power(n * n % mod, k / 2, mod);
    if (k % 2) {
        res = res * n % mod;
    }
    return res;
}

int solve(int n) {
    int64_t mod = 2 * n - 1;
    map<int64_t, int> v;
    int64_t x = 1;
    for (int i = 1; i <= 100000; i++) {
        x = 2 * x % mod;
        if (x == 1) return i;
        v[x] = i;
    }
    int64_t m = power(x, mod - 2, mod), y = 1;
    for (int i = 1; i <= 100000; i++) {
        y = y * m % mod;
        if (v[y]) {
            return 100000 * i + v[y];
        }
    }
    return -1;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        int n;
        cin >> n;
        cout << solve(n) << endl;
    }
}
0