結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー pockynypockyny
提出日時 2020-10-09 21:59:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 2,854 ms
コンパイル使用メモリ 68,500 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 16:56:51
合計ジャッジ時間 1,415 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 1 ms
4,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 29 ms
4,380 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;
int phi(int x){
    int eu = x;
    for(int 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(int a,int x,int mod){
    int 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--;
        int i,n; cin >> n;
        n = 2*n - 1;
        int m = phi(n);
        int ans = m;
        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);
                }
            }
            cout << ans << endl;
        }
    }
}
0