結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー pockynypockyny
提出日時 2020-10-09 22:05:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 68,948 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 14:41:40
合計ジャッジ時間 1,616 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>

using namespace std;
typedef long long ll;
ll phi(ll x){
    ll eu = x;
    for(ll i=2;i*i<=x;i++){
        if(x%i==0) eu /= i,eu *= (i - 1);
        while(x%i==0) x /= i;
    }
    if(x!=1) eu /= x,eu *= (x - 1);
    return eu;
}

bool solve(ll a,ll x,ll mod){
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret==1;
}

int main(){
    int t; cin >> t;
    while(t){
        t--;
        ll i,n; cin >> n;
        n = 2*n - 1;
        ll m = phi(n);
        ll ans = m + 1;
        if(n==1){
            cout << 1 << endl;
        }else{
            for(i=1;i*i<=m;i++){
                if(m%i==0){
                    if(solve(2,i,n)) ans = min(ans,i);
                    if(solve(2,m/i,n)) ans = min(ans,m/i);
                }
            }
            if(ans>m) cout << -1 << endl;
            else cout << ans << endl;
        }
    }
}
0