結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,320 KB
testcase_01 AC 79 ms
15,208 KB
testcase_02 AC 76 ms
15,100 KB
testcase_03 AC 76 ms
15,272 KB
testcase_04 AC 78 ms
15,280 KB
testcase_05 AC 76 ms
15,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 77 ms
15,276 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 75 ms
15,084 KB
testcase_17 WA -
testcase_18 AC 80 ms
15,388 KB
testcase_19 AC 76 ms
15,208 KB
testcase_20 AC 74 ms
15,180 KB
testcase_21 AC 73 ms
15,096 KB
testcase_22 AC 75 ms
15,140 KB
testcase_23 WA -
testcase_24 AC 80 ms
15,396 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 77 ms
15,200 KB
testcase_28 WA -
testcase_29 AC 80 ms
15,180 KB
testcase_30 AC 75 ms
15,352 KB
testcase_31 AC 74 ms
15,288 KB
testcase_32 AC 75 ms
15,352 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 74 ms
15,340 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
a, n, m = gets.split.map(&:to_i)
if n == 0
    puts 1 % m
    exit
end
p = a
(n % phi(m) - 1).times do
    p = modpow(a,p,m)
end
p p % m
0