結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー eve__fuyukieve__fuyuki
提出日時 2024-04-13 15:00:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 2,386 ms
コンパイル使用メモリ 198,364 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-13 15:00:59
合計ジャッジ時間 3,961 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 43 ms
6,944 KB
testcase_09 AC 44 ms
6,944 KB
testcase_10 AC 44 ms
6,940 KB
testcase_11 AC 42 ms
6,944 KB
testcase_12 AC 44 ms
6,940 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 95 ms
6,940 KB
testcase_15 AC 41 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}
long long pow_mod(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n /= 2;
    }
    return res;
}
int main() {
    fast_io();
    int t;
    cin >> t;
    for (; t--;) {
        long long n;
        cin >> n;
        vector<long long> pf;
        long long n_tmp = 2 * n - 1;
        for (long long i = 2; i * i <= n_tmp; i++) {
            if (n_tmp % i == 0) {
                pf.push_back(i);
                while (n_tmp % i == 0) {
                    n_tmp /= i;
                }
            }
        }
        if (n_tmp > 1) {
            pf.push_back(n_tmp);
        }
        long long phi = 2 * n - 1;
        for (long long p : pf) {
            phi = phi / p * (p - 1);
        }
        vector<long long> fac;
        for (long long i = 1; i * i <= phi; i++) {
            if (phi % i == 0) {
                fac.push_back(i);
                if (i * i != phi) {
                    fac.push_back(phi / i);
                }
            }
        }
        long long ans = phi;
        for (long long a : fac) {
            if (pow_mod(2, a, 2 * n - 1) == 1) {
                ans = min(ans, a);
            }
        }
        cout << ans << "\n";
    }
}
0