結果

問題 No.181 A↑↑N mod M
ユーザー 小指が強い人小指が強い人
提出日時 2016-08-24 12:18:20
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 573 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2024-04-25 15:03:34
合計ジャッジ時間 20,596 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
12,160 KB
testcase_01 AC 87 ms
12,160 KB
testcase_02 AC 94 ms
12,544 KB
testcase_03 AC 83 ms
12,288 KB
testcase_04 AC 676 ms
13,568 KB
testcase_05 AC 858 ms
13,696 KB
testcase_06 AC 85 ms
12,288 KB
testcase_07 AC 87 ms
12,160 KB
testcase_08 WA -
testcase_09 AC 507 ms
13,440 KB
testcase_10 WA -
testcase_11 AC 906 ms
13,952 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 84 ms
12,160 KB
testcase_17 WA -
testcase_18 AC 83 ms
12,288 KB
testcase_19 AC 85 ms
12,160 KB
testcase_20 AC 83 ms
12,160 KB
testcase_21 AC 85 ms
12,160 KB
testcase_22 AC 84 ms
12,160 KB
testcase_23 AC 85 ms
12,288 KB
testcase_24 AC 537 ms
13,568 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 84 ms
12,416 KB
testcase_28 WA -
testcase_29 AC 83 ms
12,160 KB
testcase_30 AC 82 ms
12,160 KB
testcase_31 AC 84 ms
12,416 KB
testcase_32 AC 83 ms
12,160 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def power(a,k,n)
  return( 0 ) if ( a == 0 || n == 0 )
  return( 0 % n ) if ( k == 0 )
  currentMod = a % n;
  currentValue = ( ( k & 1 ) > 0 ) ? currentMod : 1;
  k >>= 1
  while ( k > 0 ) do
    currentMod = ( currentMod * currentMod ) % n;
    if ( ( k & 1 ) > 0 )
      currentValue = ( currentValue * currentMod ) % n;
    end
    k >>= 1
  end
  return( currentValue );
end

def solve(a,b,m,d)
    return 1 if b == 0
    return a if b == 1 || d == 0
    mod=(m ** d)
    return power(a,solve(a,b-1,m,d-1),mod)
end

a,b,m=gets.split.map(&:to_i)
puts solve(a,b,m,140)%m
0