結果

問題 No.181 A↑↑N mod M
ユーザー yaoshimaxyaoshimax
提出日時 2015-05-09 18:37:41
言語 PyPy2
(7.3.13)
結果
AC  
実行時間 482 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 77,668 KB
実行使用メモリ 80,888 KB
最終ジャッジ日時 2023-08-15 19:02:59
合計ジャッジ時間 23,514 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 472 ms
80,576 KB
testcase_01 AC 478 ms
80,416 KB
testcase_02 AC 473 ms
80,412 KB
testcase_03 AC 475 ms
80,496 KB
testcase_04 AC 474 ms
80,540 KB
testcase_05 AC 477 ms
80,456 KB
testcase_06 AC 473 ms
80,536 KB
testcase_07 AC 476 ms
80,432 KB
testcase_08 AC 473 ms
80,368 KB
testcase_09 AC 476 ms
80,484 KB
testcase_10 AC 482 ms
80,540 KB
testcase_11 AC 479 ms
80,468 KB
testcase_12 AC 475 ms
80,468 KB
testcase_13 AC 474 ms
80,324 KB
testcase_14 AC 473 ms
80,408 KB
testcase_15 AC 475 ms
80,500 KB
testcase_16 AC 474 ms
80,416 KB
testcase_17 AC 480 ms
80,488 KB
testcase_18 AC 480 ms
80,456 KB
testcase_19 AC 478 ms
80,348 KB
testcase_20 AC 475 ms
80,304 KB
testcase_21 AC 475 ms
80,344 KB
testcase_22 AC 475 ms
80,300 KB
testcase_23 AC 476 ms
80,320 KB
testcase_24 AC 474 ms
80,432 KB
testcase_25 AC 476 ms
80,416 KB
testcase_26 AC 474 ms
80,428 KB
testcase_27 AC 475 ms
80,524 KB
testcase_28 AC 475 ms
80,416 KB
testcase_29 AC 477 ms
80,348 KB
testcase_30 AC 473 ms
80,552 KB
testcase_31 AC 478 ms
80,612 KB
testcase_32 AC 474 ms
80,644 KB
testcase_33 AC 473 ms
80,888 KB
testcase_34 AC 473 ms
80,344 KB
testcase_35 AC 474 ms
80,380 KB
testcase_36 AC 475 ms
80,340 KB
testcase_37 AC 475 ms
80,392 KB
testcase_38 AC 473 ms
80,484 KB
testcase_39 AC 474 ms
80,544 KB
testcase_40 AC 476 ms
80,484 KB
testcase_41 AC 476 ms
80,392 KB
testcase_42 AC 474 ms
80,460 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 M==1:
        return 0
    if N==0:
        return 1
    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