結果

問題 No.181 A↑↑N mod M
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-09 18:36:09
言語 PyPy2
(7.3.15)
結果
WA  
実行時間 -
コード長 913 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 77,432 KB
実行使用メモリ 80,928 KB
最終ジャッジ日時 2023-09-19 09:33:37
合計ジャッジ時間 25,717 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 505 ms
80,596 KB
testcase_01 AC 484 ms
80,748 KB
testcase_02 AC 484 ms
80,388 KB
testcase_03 AC 480 ms
80,240 KB
testcase_04 AC 481 ms
80,480 KB
testcase_05 AC 480 ms
80,560 KB
testcase_06 AC 482 ms
80,356 KB
testcase_07 AC 485 ms
80,564 KB
testcase_08 AC 482 ms
80,500 KB
testcase_09 AC 479 ms
80,288 KB
testcase_10 AC 479 ms
80,500 KB
testcase_11 AC 481 ms
80,608 KB
testcase_12 AC 483 ms
80,480 KB
testcase_13 AC 480 ms
80,580 KB
testcase_14 AC 483 ms
80,400 KB
testcase_15 AC 481 ms
80,236 KB
testcase_16 AC 481 ms
80,392 KB
testcase_17 AC 481 ms
80,500 KB
testcase_18 AC 488 ms
80,404 KB
testcase_19 AC 483 ms
80,348 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 488 ms
80,320 KB
testcase_23 AC 482 ms
80,472 KB
testcase_24 AC 481 ms
80,568 KB
testcase_25 AC 480 ms
80,460 KB
testcase_26 AC 482 ms
80,616 KB
testcase_27 AC 483 ms
80,240 KB
testcase_28 AC 483 ms
80,928 KB
testcase_29 AC 479 ms
80,716 KB
testcase_30 AC 482 ms
80,580 KB
testcase_31 AC 478 ms
80,620 KB
testcase_32 AC 485 ms
80,608 KB
testcase_33 AC 486 ms
80,404 KB
testcase_34 AC 483 ms
80,584 KB
testcase_35 AC 481 ms
80,520 KB
testcase_36 AC 483 ms
80,620 KB
testcase_37 AC 483 ms
80,276 KB
testcase_38 AC 486 ms
80,252 KB
testcase_39 AC 486 ms
80,612 KB
testcase_40 AC 945 ms
80,480 KB
testcase_41 AC 984 ms
80,368 KB
testcase_42 AC 987 ms
80,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def gcd(i,j):
    if j<i:
        return gcd(j,i)
    if j%i==0:
        return i
    else:
        return gcd(j%i,i)

def getint(i):
    ret=0
    for j in range(i-1,0,-1):
        if gcd(j,i)==1:
            ret+=1   
    return ret
interval=[getint(i) for i in range(0,2001)]

def getExpWithUpperBound(A,N,M):
    if N==0:
        return min(1,M)
    if N==1:
        return min(A,M)
    if N==2 and A<=16:
        return min(pow(A,A),M)
    if N==3 and A<=3:
        return min(pow(A,pow(A,A)),M)
    if N==4 and A<=2:
        return min(pow(A,pow(A,pow(A,A))),M)
    else:
        return M

def hypermod(A,N,M):
    #print A,N,M
    if N==0:
        return 1
    if M==1:
        return 0
    e=getExpWithUpperBound(A,N-1,M)
    if e<M:
        return pow(A,e,M)
    else:
        return pow(A,M+((hypermod(A,N-1,interval[M])-M)%interval[M]),M)
    

A,N,M=map(int,raw_input().split())
print hypermod(A,N,M)
0