結果

問題 No.251 大きな桁の復習問題(1)
ユーザー むらためむらため
提出日時 2019-01-27 19:50:17
言語 Nim
(2.0.2)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,433 bytes
コンパイル時間 2,928 ms
コンパイル使用メモリ 66,488 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 03:06:29
合計ジャッジ時間 3,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 4 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 4 ms
4,380 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import sequtils,math
proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "<stdio.h>" .}

type ModInt = object
  v:int # 0~MODに収まる
const MOD = 129402307

template useModulo() =
  proc toModInt*(a:int) : ModInt =
    if a < -MOD : result.v = ((a mod MOD) + MOD) mod MOD
    elif a < 0 : result.v = a + MOD
    elif a >= MOD: result.v = a mod MOD
    else: result.v = a
  proc `+`*(a,b:ModInt) : ModInt =
    result.v = a.v + b.v
    if result.v >= MOD : result.v = result.v mod MOD
  proc `*`*(a,b:ModInt) : ModInt =
    result.v = a.v * b.v
    if result.v >= MOD : result.v = result.v mod MOD
  proc `^`*(a:ModInt,b:int) : ModInt =
    if a.v == 0 : return 0.toModInt()
    if b == 0 : return 1.toModInt()
    if b == 1 : return a
    let pow = a^(b div 2)
    if b mod 2 == 0 : return pow * pow
    return pow * pow * a
  proc `+`*(a:int,b:ModInt) : ModInt = a.toModInt() + b
  proc `+`*(a:ModInt,b:int) : ModInt = a + b.toModInt()
  proc `-`*(a:ModInt,b:int) : ModInt = a + (-b)
  proc `-`*(a,b:ModInt) : ModInt = a + (-b.v)
  proc `-`*(a:int,b:ModInt) : ModInt = a.toModInt() + (-b.v)
  proc `*`*(a:int,b:ModInt) : ModInt = a.toModInt() * b
  proc `*`*(a:ModInt,b:int) : ModInt = a * b.toModInt()
  proc `/`*(a,b:ModInt) : ModInt = a * b^(MOD-2)
  proc `$`*(a:ModInt) : string = $a.v
useModulo()


proc scan(isTrulyZero:var bool): ModInt =
  result = 0.toModInt()
  block:
    let k = getchar_unlocked()
    result = 10 * result + k.ord - '0'.ord
    isTrulyZero = k == '0'
  block:
    let k = getchar_unlocked()
    if k < '0': return
    isTrulyZero = false
    result = 10 * result + k.ord - '0'.ord
  while true:
    let k = getchar_unlocked()
    if k < '0': return
    result = 10 * result + k.ord - '0'.ord

proc scanX(isTrulyZero:var bool): int =
  const nowMOD = MOD - 1
  result = 0
  block:
    let k = getchar_unlocked()
    result = 10 * result + k.ord - '0'.ord
    isTrulyZero = k == '0'
  block:
    let k = getchar_unlocked()
    if k < '0': return
    isTrulyZero = false
    result = 10 * result + k.ord - '0'.ord
  while true:
    let k = getchar_unlocked()
    if k < '0': break
    result = 10 * result + k.ord - '0'.ord
    if result >= nowMOD : result = result mod nowMOD

var isTrulyZero = false
let n = scan(isTrulyZero)
var isTrulyZeroX = false
let m = scanX(isTrulyZeroX)
if n.v == 0 : # 0^m == 0 | x^0
  if not isTrulyZero and isTrulyZeroX : echo 1
  else: echo 0
else:echo n^m
0