結果

問題 No.642 Two Operations No.1
ユーザー むらため
提出日時 2019-01-17 21:20:45
言語 Nim
(2.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 297 bytes
コンパイル時間 2,931 ms
コンパイル使用メモリ 64,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-01 10:11:51
合計ジャッジ時間 3,893 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils,bitops
var n = stdin.readLine().parseInt()
var ans = 0
while n > 1:
  if n mod 2 == 0:
    let z = n.countTrailingZeroBits()
    ans += z
    n = n shr z
  else:
    ans += 1
    n += 1
echo ans
# 1 から始めて x2 or -1
# 10010011_1_00 -> 10010_0111 -> 10010_1000 -> 100101 ...
0