結果

問題 No.181 A↑↑N mod M
ユーザー takuktakuk
提出日時 2015-04-06 12:08:51
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 651 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 15,368 KB
最終ジャッジ日時 2023-09-17 06:11:56
合計ジャッジ時間 5,602 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
15,096 KB
testcase_01 AC 91 ms
15,336 KB
testcase_02 AC 89 ms
15,164 KB
testcase_03 AC 82 ms
15,188 KB
testcase_04 AC 82 ms
15,092 KB
testcase_05 AC 84 ms
15,244 KB
testcase_06 AC 82 ms
15,348 KB
testcase_07 AC 86 ms
15,248 KB
testcase_08 AC 80 ms
15,056 KB
testcase_09 AC 86 ms
15,308 KB
testcase_10 AC 86 ms
15,368 KB
testcase_11 AC 81 ms
15,108 KB
testcase_12 AC 83 ms
15,120 KB
testcase_13 AC 83 ms
15,140 KB
testcase_14 AC 86 ms
15,340 KB
testcase_15 AC 85 ms
15,132 KB
testcase_16 AC 81 ms
15,088 KB
testcase_17 AC 82 ms
15,236 KB
testcase_18 AC 86 ms
15,112 KB
testcase_19 AC 80 ms
15,064 KB
testcase_20 AC 84 ms
15,344 KB
testcase_21 AC 81 ms
15,140 KB
testcase_22 AC 82 ms
15,280 KB
testcase_23 AC 83 ms
15,096 KB
testcase_24 AC 88 ms
15,100 KB
testcase_25 AC 90 ms
15,144 KB
testcase_26 AC 81 ms
15,356 KB
testcase_27 AC 81 ms
15,144 KB
testcase_28 AC 84 ms
15,060 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 81 ms
15,096 KB
testcase_32 WA -
testcase_33 AC 85 ms
15,296 KB
testcase_34 AC 86 ms
15,216 KB
testcase_35 AC 85 ms
15,084 KB
testcase_36 AC 81 ms
15,248 KB
testcase_37 AC 88 ms
15,160 KB
testcase_38 AC 86 ms
15,088 KB
testcase_39 AC 81 ms
15,296 KB
testcase_40 AC 82 ms
15,204 KB
testcase_41 AC 84 ms
15,112 KB
testcase_42 AC 84 ms
15,268 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'
def phi(n)
    ps = Array.new
    Prime.each(n) do |p|
        ps.push(p) if n % p == 0
    end
    ret = n
    ps.each do |p|
        ret *= (1.0 - (1.0/p))
    end
    return ret.round
end
def modpow(b,e,m)
    res = 1
    while e > 0
        if e & 1 == 1
            res = (res * b) % m
        end
        e >>= 1
        b = (b * b) % m
    end
    res
end
def rec(a,n,m)
    return 1 if n == 0
    return 0 if m == 1
    m2 = phi(m)
    b = rec(a,n-1,m2) + m2
    return modpow(a,b,m)
end
a, n, m = gets.split.map(&:to_i)
if n == 0
    p 1 % m
elsif n == 1
    p a % m
elsif n == 2
    p modpow(a,a,m)
else
    p rec(a,n,m)
end
0