結果

問題 No.1232 2^x = x
ユーザー shakayamishakayami
提出日時 2020-11-26 20:33:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 711 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,136 KB
実行使用メモリ 78,528 KB
最終ジャッジ日時 2023-10-01 03:29:31
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,744 KB
testcase_01 AC 129 ms
77,916 KB
testcase_02 AC 711 ms
78,528 KB
testcase_03 AC 522 ms
78,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
def phi(N):
    M=N
    prime=set()
    p=2
    while(p*p<=M):
        while(M%p==0):
            M//=p
            prime.add(p)
        p+=1
    if M>1:
        prime.add(M)
    res=N
    for p in prime:
        res=(res*(p-1))//p
    return res
def lcm(x,y):
    return (x*y)//gcd(x,y)

def solve(A,M):
    if pow(A,M,M)==0:
        return M
    if A==1:
        return 1
    if M==1:
        return 1
    phiM=phi(M)
    x=solve(A,phiM)
    L=lcm(phiM,M)
    return pow(A,x,L)

Q=int(input())
for i in range(Q):
    p=int(input())
    print(solve(2,p))

    

0