結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー finefine
提出日時 2020-10-10 02:14:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,659 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 171,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 14:47:06
合計ジャッジ時間 2,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

template<typename T>
map<T, int> prime_factor(T n) {
    map<T, int> res;
    for (T i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

ll phi(ll n) {
    ll res = 1;
    for (ll i = 2; i * i <= n; i++) {
        ll foo = 1, bar = 1;
        while (n % i == 0) {
            if (foo > 1) bar *= i;
            foo *= i;
            n /= i;
        }
        if (foo > bar) res *= foo - bar;
    }
    if (n != 1) res *= n - 1;
    return res;   
}

template<typename T>
vector<T> divisor(T n) {
    vector<T> res;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        ll n;
        cin >> n;
        if (n == 1) {
            cout << 1 << newl;
            continue;
        }
        vector<ll> d = divisor(phi(2 * n - 1));
        sort(d.begin(), d.end());
        ll ans = -1;
        for (ll x : d) {
            if (modpow(2, x, 2 * n - 1) == 1) {
                ans = x;
                break;
            }
        }
        cout << ans << newl;
    }
    return 0;
}
0