結果

問題 No.1255 ハイレーツ・オブ・ボリビアン
ユーザー ayaoniayaoni
提出日時 2020-10-30 12:55:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 76,936 KB
最終ジャッジ日時 2023-09-30 14:48:45
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,872 KB
testcase_01 AC 72 ms
71,596 KB
testcase_02 AC 78 ms
75,804 KB
testcase_03 AC 78 ms
76,188 KB
testcase_04 AC 77 ms
75,748 KB
testcase_05 AC 82 ms
76,784 KB
testcase_06 AC 83 ms
76,456 KB
testcase_07 AC 83 ms
76,936 KB
testcase_08 AC 165 ms
76,580 KB
testcase_09 AC 167 ms
76,652 KB
testcase_10 AC 166 ms
76,628 KB
testcase_11 AC 164 ms
76,388 KB
testcase_12 AC 166 ms
76,392 KB
testcase_13 AC 83 ms
75,920 KB
testcase_14 AC 208 ms
76,620 KB
testcase_15 AC 162 ms
76,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def I(): return int(sys.stdin.readline().rstrip())


def phi(n):
    ans = n
    for i in range(2,int(n**.5) + 1):
        if n % i == 0:
            ans = (ans*(i-1))//i
            while n % i == 0:
                n //= i
            if n == 1:  # 時間短縮
                break
    if n != 1:
        ans = (ans*(n-1))//n
    return ans


def divisor(n):  # nの約数全列挙
    res = []
    for i in range(1,int(n**.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n//i:
                res.append(n//i)
    return res


T = I()
for _ in range(T):
    N = I()
    # 2**K == 1 (mod 2*N-1) たる最小のKを求める
    x = phi(2*N-1)
    div = divisor(x)
    div.sort()
    for d in div:
        if pow(2,d,2*N-1) == 1 or N == 1:
            print(d)
            break
0