結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー milanis48663220milanis48663220
提出日時 2020-10-11 00:47:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,347 bytes
コンパイル時間 835 ms
コンパイル使用メモリ 89,056 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 22:44:10
合計ジャッジ時間 1,940 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

template <typename T>
vector<T> prime_facs(T N) {
	vector<T> ans;
	for (int i = 2; i * i <= N; i++) {
		if (N % i == 0) {
		ans.push_back(i);
            while (N % i == 0) {
                N /= i;
            }
		}
	}
	if (N != 1) ans.push_back(N);
	return ans;
}

template <typename T>
T pow(T a, ll n, ll MOD) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}

template <typename T>
vector<T> divs(T N) {
	vector<T> ans;
	for (int i = 1; i * i <= N; i++) {
		if (N % i == 0) {
		ans.push_back(i);
		if (i * i != N) ans.push_back(N / i);
		}
	}
	return ans;
}

void solve(){
    int n; cin >> n;
    auto v = prime_facs<int>(2*n-1);
    int m = 2*n-1;
    for(int i : v){
        m = (m/i)*(i-1);
    }
    auto u = divs<int>(m);
    sort(u.begin(), u.end());
    for(int k : u){
        if(pow<ll>(2, k, 2*n-1) == 1){
            cout << k << endl;
            return;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    for(int i = 0; i < t; i++) solve();
}
0