結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー 👑 NachiaNachia
提出日時 2020-10-09 22:39:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 793 ms / 2,000 ms
コード長 608 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 172,300 KB
実行使用メモリ 5,208 KB
最終ジャッジ日時 2023-09-30 14:43:39
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 4 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 108 ms
4,608 KB
testcase_06 AC 134 ms
4,840 KB
testcase_07 AC 113 ms
4,904 KB
testcase_08 AC 506 ms
4,912 KB
testcase_09 AC 511 ms
4,892 KB
testcase_10 AC 505 ms
5,208 KB
testcase_11 AC 514 ms
4,976 KB
testcase_12 AC 511 ms
4,916 KB
testcase_13 AC 29 ms
4,980 KB
testcase_14 AC 793 ms
4,976 KB
testcase_15 AC 501 ms
5,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

#include<unordered_map>

LL loop(ULL N) {
	if (N == 1) return 1;
	N = 2 * N - 1;
	unordered_map<ULL, ULL> X(40000);
	ULL p = 1;
	rep(i, 40000) { X[p] = i; p = p * 2 % N; if (p == 1) return i + 1; }
	p = 1;
	ULL q = 1; rep(i, 40000) q = q * (N / 2 + 1) % N;
	rep(i, 60000) {
		p = p * q % N;
		if (X.count(p)) return (i + 1) * 40000 + X[p];
	}
	return -1;
}

int main() {
	int T; cin >> T;
	while (T--) {
		ULL N; cin >> N;
		cout << loop(N) << endl;
	}

	return 0;
}
0