結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー anagohirameanagohirame
提出日時 2020-10-09 23:53:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 594 bytes
コンパイル時間 705 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 76,404 KB
最終ジャッジ日時 2023-09-30 14:45:52
合計ジャッジ時間 3,406 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,084 KB
testcase_01 AC 72 ms
71,080 KB
testcase_02 AC 76 ms
76,212 KB
testcase_03 AC 77 ms
75,556 KB
testcase_04 AC 74 ms
75,244 KB
testcase_05 AC 83 ms
75,984 KB
testcase_06 AC 84 ms
76,052 KB
testcase_07 AC 82 ms
75,968 KB
testcase_08 AC 178 ms
76,072 KB
testcase_09 AC 177 ms
75,972 KB
testcase_10 AC 181 ms
76,220 KB
testcase_11 AC 179 ms
76,404 KB
testcase_12 AC 182 ms
76,344 KB
testcase_13 AC 82 ms
75,780 KB
testcase_14 AC 218 ms
76,104 KB
testcase_15 AC 178 ms
76,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def input():
	return sys.stdin.buffer.readline()[:-1]

def phi(x):
	prime = []
	i = 2
	y = x
	while i*i <= x:
		if y%i == 0:
			prime.append(i)
			while y%i == 0:
				y //= i
		i += 1

	if y > 1:
		prime.append(y)
	res = x
	for p in prime:
		res = res * (p-1) // p

	div = []
	i = 1
	while i * i <= res:
		if res % i == 0:
			div.append(i)
			div.append(res // i)
		i += 1
	return div

for _ in range(int(input())):
	n = int(input()) * 2
	if n == 2:
		print(1)
		continue
	div = phi(n-1)
	#print(div)
	ans = n
	for d in div:
		if pow(2, d, n-1) == 1:
			ans = min(ans, d)
	print(ans)
0