結果

問題 No.639 An Ordinary Sequence
ユーザー むらためむらため
提出日時 2019-01-27 14:38:38
言語 Nim
(2.0.2)
結果
AC  
実行時間 7 ms / 1,000 ms
コード長 592 bytes
コンパイル時間 4,531 ms
コンパイル使用メモリ 66,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 13:04:38
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}
proc scan(): int =
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord

proc solve(n:int):int =
  if n == 0 : return 1
  if n <= 15: return solve(n div 3) + solve(n div 5)
  # (3 5) (3 5) => (9 15 15 25)
  if n <= 225: return 2 * solve(n div 15) + solve(n div 25) + solve(n div 9)
  # (3 5) (3 5) (3 5) => (9 2*15 25)(3 5) => (27 3*45 3*75 125)
  return 3 * solve(n div 75) + 3 * solve(n div 45) + solve(n div 125) + solve(n div 27)

echo solve(scan())
0