結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー trineutrontrineutron
提出日時 2020-10-09 23:01:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,764 ms / 2,000 ms
コード長 679 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 205,272 KB
実行使用メモリ 7,988 KB
最終ジャッジ日時 2023-09-27 20:20:21
合計ジャッジ時間 9,914 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 144 ms
5,324 KB
testcase_06 AC 192 ms
5,472 KB
testcase_07 AC 158 ms
5,500 KB
testcase_08 AC 826 ms
6,432 KB
testcase_09 AC 827 ms
5,780 KB
testcase_10 AC 807 ms
5,856 KB
testcase_11 AC 851 ms
7,852 KB
testcase_12 AC 873 ms
7,800 KB
testcase_13 AC 47 ms
5,600 KB
testcase_14 AC 1,764 ms
7,988 KB
testcase_15 AC 815 ms
5,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int64_t solve(int64_t n) {
    if (n == 1) return 1;
    constexpr int64_t sz = 50000;
    int64_t mod = 2 * n - 1;
    unordered_map<int64_t, int64_t> v;
    int64_t x = 1, m = 1;
    v[1] = 0;
    for (int i = 1; i <= sz; i++) {
        x = 2 * x % mod;
        m = n * m % mod;
        if (x == 1) return i;
        v[x] = i;
    }
    int64_t y = 1;
    for (int i = 1; ; i++) {
        y = y * m % mod;
        if (v[y]) {
            return sz * i + v[y];
        }
    }
}

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