結果
問題 | No.181 A↑↑N mod M |
ユーザー | __math |
提出日時 | 2015-04-06 01:34:49 |
言語 | Python2 (2.7.18) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,591 bytes |
コンパイル時間 | 48 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 9,344 KB |
最終ジャッジ日時 | 2024-07-04 03:07:13 |
合計ジャッジ時間 | 3,149 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
9,216 KB |
testcase_01 | AC | 34 ms
9,216 KB |
testcase_02 | AC | 33 ms
9,216 KB |
testcase_03 | AC | 35 ms
9,344 KB |
testcase_04 | AC | 35 ms
9,088 KB |
testcase_05 | AC | 36 ms
9,344 KB |
testcase_06 | AC | 36 ms
9,344 KB |
testcase_07 | AC | 34 ms
9,216 KB |
testcase_08 | WA | - |
testcase_09 | AC | 34 ms
9,088 KB |
testcase_10 | AC | 34 ms
9,216 KB |
testcase_11 | AC | 34 ms
9,088 KB |
testcase_12 | AC | 33 ms
9,216 KB |
testcase_13 | AC | 35 ms
9,216 KB |
testcase_14 | AC | 35 ms
9,216 KB |
testcase_15 | AC | 35 ms
9,216 KB |
testcase_16 | AC | 37 ms
9,216 KB |
testcase_17 | AC | 36 ms
9,216 KB |
testcase_18 | AC | 36 ms
9,344 KB |
testcase_19 | AC | 36 ms
9,088 KB |
testcase_20 | AC | 36 ms
9,216 KB |
testcase_21 | AC | 37 ms
9,216 KB |
testcase_22 | AC | 36 ms
9,216 KB |
testcase_23 | WA | - |
testcase_24 | AC | 37 ms
9,088 KB |
testcase_25 | AC | 38 ms
9,216 KB |
testcase_26 | AC | 38 ms
9,216 KB |
testcase_27 | AC | 37 ms
9,216 KB |
testcase_28 | WA | - |
testcase_29 | AC | 36 ms
9,216 KB |
testcase_30 | AC | 36 ms
9,216 KB |
testcase_31 | AC | 36 ms
9,088 KB |
testcase_32 | AC | 35 ms
9,216 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 36 ms
9,088 KB |
testcase_38 | WA | - |
testcase_39 | AC | 36 ms
9,216 KB |
testcase_40 | AC | 37 ms
9,216 KB |
testcase_41 | WA | - |
testcase_42 | AC | 36 ms
9,216 KB |
ソースコード
#coding=utf-8 import time import math from fractions import gcd def primes(n): return list(i_primes(n)) def i_primes(n): p = [True] * (n+1) p[0] = p[1] = False max = int(math.sqrt(n+1)) for i in xrange(2,max): if p[i]: yield i for j in xrange(i*2,n+1,i): p[j] = False for i in xrange(max,n+1): if p[i]: yield i pr = primes(10**5) def euler_phi(n): ret = n for i in pr: if i*i > n: break if n % i == 0: while n%i==0: n/=i ret = ret/i*(i-1) if n != 1: ret = ret/n*(n-1) return ret def p_factor(n): ret = [] for p in pr: if p * p > n: break if n % p == 0: ret.append(p) while n % p == 0: n /= p return ret def tetration(a,b,mod): if b == 0: return 1 return pow(a,tetration(a,b-1,euler_phi(mod)),mod) def tetration2(a,b,mod): if b == 0 or a == 1: return 1 ret = 1 while ret < 20 and b > 0: ret = pow(a,ret) b -= 1 if b == 0: return ret g = gcd(a,mod) g_factor = p_factor(g) a_rem = a a_div = 1 for gf in g_factor: while a_rem % gf == 0: a_rem /= gf a_div *= gf dp = [mod] for i in xrange(1,b): dp.append(euler_phi(dp[i-1])) if dp[-1] == 1: break for i in reversed(dp): ret = pow(a_rem,ret,i) return ret * a_div % mod def main(): a,n,m = map(int,raw_input().split()) print tetration2(a,n,m) % m main()