結果

問題 No.741 AscNumber(Easy)
ユーザー chaemonchaemon
提出日時 2020-09-14 21:21:12
言語 Nim
(2.0.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 4,202 bytes
コンパイル時間 4,601 ms
コンパイル使用メモリ 66,748 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 00:56:13
合計ジャッジ時間 4,727 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 1 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,940 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 2 ms
6,944 KB
testcase_35 AC 1 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 1 ms
6,940 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 1 ms
6,940 KB
testcase_41 AC 1 ms
6,944 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 1 ms
6,944 KB
testcase_44 AC 2 ms
6,944 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 1 ms
6,944 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 AC 1 ms
6,940 KB
testcase_51 AC 1 ms
6,940 KB
testcase_52 AC 1 ms
6,944 KB
testcase_53 AC 2 ms
6,944 KB
testcase_54 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# verify-helper: PROBLEM https://yukicoder.me/problems/no/741

when not defined ATCODER_MODINT_HPP:
  const ATCODER_MODINT_HPP* = 1

  type
    ModInt*[M: static[int]] = distinct uint32

  proc `$`*[M: static[int]](m: ModInt[M]): string {.inline.} =
    $m.int

  #proc modulo*(x, y: int): int {.inline.} =
  #  ## requires: y > 0
  #  assert y > 0
  #  if x < 0:
  #    let tmp = (-x) mod y
  #    if tmp == 0:
  #      0
  #    else:
  #      y - tmp
  #  else:
  #    x mod y

  #proc extgcd*(x, y: int): (int, int) {.inline.} =
  #  var
  #    a = x
  #    p = y
  #    b, r = 1
  #    c, q = 0
  #  while a mod p != 0:
# #   while a.modulo(p) != 0:
  #    let t = a div p
  #    a -= p * t
  #    b -= q * t
  #    c -= r * t
  #    swap(a, p)
  #    swap(b, q)
  #    swap(c, r)
  #  (q, r)

  proc initModInt*(v: SomeInteger or ModInt; M: static[int] = 1_000_000_007): ModInt[M] {.inline.} =
    when v is ModInt: return v
    else:
      if 0 <= v:
        if v < M: return ModInt[M](v.uint32)
        else: return ModInt[M]((v mod M).uint32)
      else:
        var v = v mod M
        if v < 0: v += M
        return ModInt[M](v.uint32)

  proc initModIntRaw*(v: SomeInteger; M: static[int] = 1_000_000_007): ModInt[M] {.inline.} =
    ModInt[M](v.uint32)

  proc inv[M:static[int]](v:ModInt[M]):ModInt[M] {.inline.} =
    var
      a = initModInt(v, M).int
      b = M
      u = 1
      v = 0
    while b > 0:
      let t = a div b
      a -= t * b;swap(a, b)
      u -= t * v;swap(u, v)
    return initModInt(u, M)

#  proc retake*[M: static[int]](m: var ModInt[M]) {.inline.} =
#    int(m) = int(m).modulo(M)

  proc val*[M: static[int]](m: ModInt[M]): int {.inline.} =
    int(m)

  proc modulo*[M: static[int]](m: ModInt[M]): int {.inline.} =
    M

  proc `-`*[M: static[int]](m: ModInt[M]): ModInt[M] {.inline.} =
    if int(m) == 0: return m
    else: return ModInt[M](M - int(m))

  template generateDefinitions(name, l, r, retType, body: untyped): untyped =
    proc name*[M: static[int]](l: ModInt[M]; r: ModInt[M]): retType {.inline.} =
      body
    proc name*[M: static[int]](l: SomeInteger; r: ModInt[M]): retType {.inline.} =
      body
    proc name*[M: static[int]](l: ModInt[M]; r: SomeInteger): retType {.inline.} =
      body

#  proc inv*[M: static[int]](m: ModInt[M]): ModInt[M] {.inline.} =
#    result = initModInt(extgcd(M, int(m))[1], M)

  proc `+=`*[M: static[int]](m: var ModInt[M]; n: SomeInteger | ModInt[M]) {.inline.} =
    uint32(m) += initModInt(n, M).uint32
    if uint32(m) >= M.uint32: uint32(m) -= M.uint32

  proc `-=`*[M: static[int]](m: var ModInt[M]; n: SomeInteger | ModInt[M]) {.inline.} =
    uint32(m) += M.uint32 - initModInt(n, M).uint32
    if uint32(m) >= M.uint32: uint32(m) -= M.uint32

  proc `*=`*[M: static[int]](m: var ModInt[M]; n: SomeInteger | ModInt[M]) {.inline.} =
    uint32(m) = (int(m) * initModInt(n, M).int mod M).uint32
#    m.retake()

  proc `/=`*[M: static[int]](m: var ModInt[M]; n: SomeInteger | ModInt[M]) {.inline.} =
    uint32(m) = (int(m) * initModInt(n, M).inv().int mod M).uint32
#    m.retake()

  generateDefinitions(`+`, m, n, ModInt[M]):
    result = initModInt(m, M)
    result += n

  generateDefinitions(`-`, m, n, ModInt[M]):
    result = initModInt(m, M)
    result -= n

  generateDefinitions(`*`, m, n, ModInt[M]):
    result = initModInt(m, M)
    result *= n

  generateDefinitions(`/`, m, n, ModInt[M]):
    result = initModInt(m, M)
    result /= n

  proc `==`*[M: static[int]](m: ModInt[M]; n: SomeInteger | ModInt[M]): bool {.inline.} =
    int(m) == initModInt(n, M).int

  proc inc*[M: static[int]](m: var ModInt[M]) {.inline.} =
    uint32(m).inc
    if m == M:
      uint32(m) = 0

  proc dec*[M: static[int]](m: var ModInt[M]) {.inline.} =
    if m == 0:
      uint32(m) = M - 1
    else:
      uint32(m).dec

  proc pow*[M: static[int]](m: ModInt[M]; p: SomeInteger): ModInt[M] {.inline.} =
    var
      p = p.int
      m = m
    uint32(result) = 1
    while p > 0:
      if (p and 1) == 1:
        result *= m
      m *= m
      p = p shr 1



import strutils, sequtils, math

let
  N = stdin.readLine.parseInt.initModInt()

echo (0 ..< 9).mapIt(N + 9 - it).prod / toSeq(1 .. 9).prod
0