結果

問題 No.167 N^M mod 10
ユーザー urutomurutom
提出日時 2019-04-13 15:56:30
言語 Ruby
(3.3.0)
結果
AC  
実行時間 139 ms / 1,000 ms
コード長 237 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 11,864 KB
実行使用メモリ 30,128 KB
最終ジャッジ日時 2023-10-22 00:28:57
合計ジャッジ時間 4,679 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
16,088 KB
testcase_01 AC 86 ms
16,088 KB
testcase_02 AC 138 ms
30,128 KB
testcase_03 AC 136 ms
30,128 KB
testcase_04 AC 136 ms
30,128 KB
testcase_05 AC 84 ms
16,088 KB
testcase_06 AC 83 ms
16,088 KB
testcase_07 AC 82 ms
16,088 KB
testcase_08 AC 82 ms
16,088 KB
testcase_09 AC 81 ms
16,088 KB
testcase_10 AC 82 ms
16,088 KB
testcase_11 AC 82 ms
16,088 KB
testcase_12 AC 82 ms
16,084 KB
testcase_13 AC 84 ms
16,088 KB
testcase_14 AC 83 ms
16,088 KB
testcase_15 AC 83 ms
16,088 KB
testcase_16 AC 84 ms
16,088 KB
testcase_17 AC 81 ms
16,088 KB
testcase_18 AC 87 ms
16,088 KB
testcase_19 AC 87 ms
16,088 KB
testcase_20 AC 83 ms
16,088 KB
testcase_21 AC 85 ms
16,088 KB
testcase_22 AC 139 ms
30,124 KB
testcase_23 AC 139 ms
30,124 KB
testcase_24 AC 137 ms
30,124 KB
testcase_25 AC 136 ms
30,124 KB
testcase_26 AC 83 ms
16,088 KB
testcase_27 AC 137 ms
30,124 KB
testcase_28 AC 138 ms
30,124 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.chomp[-1].to_i
m=gets.to_i
#trivial
if [0,1,5,6]===n
  puts n
  exit
#Euler's theorem
elsif [3,7,9]===n
  m%=4
  puts (n**m)%10
else
  prod=1
  while m>0
    prod=(prod*n)%10 if m.odd?
    m/=2
    n=(n*n)%10
  end
  puts prod
end
0