結果
問題 |
No.181 A↑↑N mod M
|
ユーザー |
![]() |
提出日時 | 2016-08-24 12:14:01 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 572 bytes |
コンパイル時間 | 459 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,288 KB |
最終ジャッジ日時 | 2024-11-08 01:50:40 |
合計ジャッジ時間 | 5,792 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 18 WA * 19 |
コンパイルメッセージ
Syntax OK
ソースコード
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,20)%m