結果

問題 No.2269 eN!の整数部分の下1桁
ユーザー tomeruntomerun
提出日時 2023-04-14 22:30:48
言語 Crystal
(1.11.2)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 427 bytes
コンパイル時間 12,723 ms
コンパイル使用メモリ 296,552 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 20:02:39
合計ジャッジ時間 14,490 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 137 ms
5,376 KB
testcase_19 AC 132 ms
5,376 KB
testcase_20 AC 137 ms
5,376 KB
testcase_21 AC 134 ms
5,376 KB
testcase_22 AC 135 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

require "big"

read_line.to_i.times do
  n = read_line.to_i64
  if n == 0
    puts 2
    next
  end
  ans = 0i64
  mul = 1i64
  m = n
  while m >= 0
    ans += mul
    mul *= m
    m -= 1
    mul %= 10
    if mul == 0
      break
    end
  end
  puts ans % 10
end

def naive(n)
  mul = BigInt.new(1)
  sum = 0i64
  n.downto(1) do |i|
    sum += (mul % 10).to_i
    mul *= i
  end
  sum += (mul % 10).to_i
  return sum % 10
end
0