結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー shinchanshinchan
提出日時 2022-12-26 12:06:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 1,430 bytes
コンパイル時間 2,424 ms
コンパイル使用メモリ 208,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 22:28:49
合計ジャッジ時間 3,418 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;


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


ll phi(ll n) {
    ll m = n;
    ll ans = 1;
    for(ll i = 2; i * i <= n; i ++) {
        if(m % i == 0) {
            m /= i;
            ans *= (i - 1);
        } else continue;
        while(m % i == 0) {
            m /= i;
            ans *= i;
        }
    }
    if(m > 1) ans *= m - 1;
    return ans;
}

vector<ll> divisor(ll n) {
    vector<ll> v;
    for(ll i = 1; i * i <= n ; i ++) {
        if(n % i == 0) {
            if(i * i != n) v.pb(n / i);
            v.pb(i);
        }
    }
    return v;
}
void solve() {
    ll n;
    cin >> n;
    if(n == 1) {
        cout << 1 << endl;
        return ;
    }

    auto v = divisor(phi(n * 2 - 1));
    sort(be(v));
    all(e, v) {
        if(modpow(2LL, e, n * 2 - 1) == 1LL) {
            cout << e << endl;
            return ;
        } 
    }
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false); 
    int t;
    cin >> t;
    while(t--) solve();
    return 0; 
}
0