結果
問題 | No.822 Bitwise AND |
ユーザー | nadeshino |
提出日時 | 2019-04-26 22:19:45 |
言語 | Nim (2.0.2) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,653 bytes |
コンパイル時間 | 1,250 ms |
コンパイル使用メモリ | 81,224 KB |
最終ジャッジ日時 | 2024-11-14 21:25:58 |
合計ジャッジ時間 | 1,826 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 19) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated] /home/judge/data/code/Main.nim(118, 18) Warning: Deprecated since v0.20, use 'toHashSet'; toSet is deprecated [Deprecated] stack trace: (most recent call last) Main.nim(13, 9) unpack /home/judge/data/code/Main.nim(119, 19) template/generic instantiation of `input` from here /home/judge/data/code/Main.nim(19, 41) template/generic instantiation of `unpack` from here /home/judge/data/code/Main.nim(13, 9) Error: index 1 not in 0 .. 0
ソースコード
import algorithm, future, hashes, macros, math, sequtils, sets, strutils, tables, times, unicode proc `%=`(n: var int, m: int) = n = n mod m proc `//=`(n: var int, m: int) = n = n div m proc `<<=`(n: var int, m: int) = n = n shl m proc `>>=`(n: var int, m: int) = n = n shr m proc `<?=`(n: var int, m: int) = n = min(n, m) proc `>?=`(n: var int, m: int) = n = max(n, m) macro unpack*(rhs: seq, cnt: static[int]): auto = let t = genSym(); result = quote do:(let `t` = `rhs`;()) if NimMinor <= 17: for i in 0..<cnt: result[0][1].add(quote do:`t`[`i`]) else: for i in 0..<cnt: result[1].add(quote do:`t`[`i`]) template input*(typ: typedesc, cnt: Natural = 1): untyped = let line = stdin.readLine.split(" ") when typ is int: line.map(parseInt).unpack(cnt) elif typ is float: line.map(parseFloat).unpack(cnt) elif typ is string: line.unpack(cnt) elif typ is char: line.mapIt(it[0]).unpack(cnt) template inputs*(typ: typedesc): untyped = let line = stdin.readLine.split(" ") when typ is int: line.map(parseInt) elif typ is float: line.map(parseFloat) elif typ is string: line elif typ is char: line.mapIt(it[0]) # -------------------------------------------------- # const modulus = 10 ^ 9 + 7 type ModInt* = object v: int proc initModInt*(n: int): ModInt = result.v = (n mod modulus + modulus) mod modulus proc `$`*(x: ModInt): string = $x.v proc pow*(x: ModInt, n: int): ModInt = if n < 0: return pow(x, -n).pow(modulus - 2) var p = 1 var x = x.v var n = n while n > 0: if (n and 1) != 0: p = p * x mod modulus x = x * x mod modulus n = n shr 1 result.v = p proc inverse*(x: ModInt): ModInt = pow(x, modulus - 2) proc `+`*(x: ModInt): ModInt = result.v = x.v proc `-`*(x: ModInt): ModInt = result.v = modulus - x.v if result.v == modulus: result.v = 0 proc `+`*(a: ModInt, b: ModInt): ModInt = result.v = a.v + b.v if result.v >= modulus: result.v -= modulus proc `-`*(a: ModInt, b: ModInt): ModInt = result.v = a.v - b.v if result.v < 0: result.v += modulus proc `*`*(a: ModInt, b: ModInt): ModInt = result.v = a.v * b.v if result.v >= modulus: result.v = result.v mod modulus proc `/`*(a: ModInt, b: ModInt): ModInt = result.v = a.v * b.inverse().v if result.v >= modulus: result.v = result.v mod modulus proc `+`*(a: ModInt, b: int): ModInt = a + initModInt(b) proc `-`*(a: ModInt, b: int): ModInt = a - initModInt(b) proc `*`*(a: ModInt, b: int): ModInt = a * initModInt(b) proc `/`*(a: ModInt, b: int): ModInt = a / initModInt(b) proc `+`*(a: int, b: ModInt): ModInt = initModInt(a) + b proc `-`*(a: int, b: ModInt): ModInt = initModInt(a) - b proc `*`*(a: int, b: ModInt): ModInt = initModInt(a) * b proc `/`*(a: int, b: ModInt): ModInt = initModInt(a) / b proc `+=`*(a: var ModInt; b: ModInt) = a = a + b proc `-=`*(a: var ModInt; b: ModInt) = a = a - b proc `*=`*(a: var ModInt; b: ModInt) = a = a * b proc `/=`*(a: var ModInt; b: ModInt) = a = a / b proc `+=`*(a: var ModInt; b: int) = a = a + b proc `-=`*(a: var ModInt; b: int) = a = a - b proc `*=`*(a: var ModInt; b: int) = a = a * b proc `/=`*(a: var ModInt; b: int) = a = a / b # -------------------------------------------------- # var powerOfTwo = toSet([1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]) var (N, K) = input(int, 2) var popo: int if N in powerOfTwo: popo = N * 2 else: popo = nextPowerOfTwo(N) if (popo + N) - (popo - 1) <= K: echo "INF" quit(0) var res = 0 for x in countup(N, popo - 1): for y in countup(x, x + K): if (x and y) == N: inc res echo res