結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー trineutrontrineutron
提出日時 2020-10-09 22:50:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 804 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 205,600 KB
実行使用メモリ 13,368 KB
最終ジャッジ日時 2023-09-27 18:49:07
合計ジャッジ時間 15,657 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 5 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
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 <= 50000; 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 <= 50000; i++) {
        y = y * m % mod;
        if (v[y]) {
            return 50000 * 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