結果

問題 No.1232 2^x = x
ユーザー LyricalMaestro
提出日時 2025-01-03 00:55:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 71,552 KB
最終ジャッジ日時 2025-01-03 00:55:37
合計ジャッジ時間 2,579 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/1232

import math

def solve(p):
    if p == 2:
        return 2

    sqrt_p = int(math.sqrt(p - 1))
    divisors = []
    for x in range(1, sqrt_p + 1):
        if (p - 1) % x == 0:
            q = (p - 1) // x
            divisors.append(x)
            if q != x:
                divisors.append(q)
    divisors.sort()
    min_d = -1
    for d in divisors:
        if pow(2, d, p) == 1:
            min_d = d
            break
    
    ans = pow(min_d, p - 2, p)
    ans = ans * min_d
    return ans





def main():
    N = int(input())
    answers = []
    for _ in range(N):
        p = int(input())
        ans = solve(p)
        answers.append(ans)

    for ans in answers:
        print(ans)
           

    


        




if __name__ == "__main__":
    main()
0