Submit Info #45815

Problem Lang User Status Time Memory
Tetration Mod pypy3 shakayami AC 450 ms 33.20 MiB

ケース詳細
Name Status Time Memory
example_00 AC 50 ms 29.85 MiB
example_01 AC 51 ms 29.85 MiB
max_00 AC 169 ms 33.06 MiB
max_01 AC 168 ms 32.09 MiB
max_02 AC 170 ms 32.89 MiB
max_1000000000_00 AC 117 ms 32.52 MiB
max_1000000000_01 AC 119 ms 32.31 MiB
max_1000000000_02 AC 128 ms 32.32 MiB
max_998244353_00 AC 450 ms 32.80 MiB
max_998244353_01 AC 449 ms 32.76 MiB
max_998244353_02 AC 433 ms 33.20 MiB
random_00 AC 139 ms 32.31 MiB
random_01 AC 87 ms 31.50 MiB
random_02 AC 77 ms 31.55 MiB
random_03 AC 90 ms 32.73 MiB
random_04 AC 127 ms 33.05 MiB
small_00 AC 82 ms 30.59 MiB

def phi(N): res=N i=2 while(i*i<=N): if N%i==0: res-=res//i while(N%i==0): N//=i i+=1 if N>1: res-=res//N return res def solve(A,B,M): if A==0:return ((B+1)%2)%M if M==1:return 0 if B==0:return 1 if B==1:return A%M if B==2:return pow(A,A,M) phiM=phi(M) tmp=solve(A,B-1,phiM) if tmp==0:tmp+=phiM return pow(A,tmp,M) T=int(input()) for i in range(T): a,b,m=map(int,input().split()) print(solve(a,b,m))