아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Add and Reverse

시간 제한1초메모리 제한1024 MB

요약
0에서 시작해 주어진 32비트 n에 도달하는 최소 연산 횟수를 구한다. 각 연산은 1 더하기(2^32 모듈로) 또는 32비트 뒤집기 중 하나다.
난이도

보통10점 중 7점

유형
BFS, 그래프, 최단 경로, 비트 연산
정답자
아직 제출이 없습니다

문제

Consider a non-negative integer xx stored in 3232 bits of memory: x=b_31⋅231+b_30⋅230+…+b_2⋅22+b_1⋅21+b_0⋅20x = b\_{31} \cdot 2^{31} + b\_{30} \cdot 2^{30} + \ldots + b\_{2} \cdot 2^{2} + b\_{1} \cdot 2^{1} + b\_{0} \cdot 2^{0} where each bit b_ib\_{i} can take two values 00 and 11 independently of other bits.

We perform a sequence of operations with this integer, possibly an empty one. In one operation, we can either increase the number by one or reverse the bits constituting it: swap 3131-st bit and 00-th bit, swap 3030-th bit and first bit, …\ldots, swap 1616-th bit and 1515-th bit. We can perform any number of any of these two operations in any order.

What is the minimum possible number of operations required to transform a zero to the given integer nn?

The increasing by one is carried out modulo 2322^{32}, which means that, if the current number is equal to 232−12^{32} - 1, increasing it by one produces a zero.

입력

The only line contains an integer nn (0≤n<2320 \le n < 2^{32}).

출력

Print one integer: the minimum possible number of operations required to transform a zero to the given integer nn.

힌트

In the first example, the fastest way to get a 55 is to increase the number by one five times.

In the second example, we start by producing a one, and then reverse the bits, turning 1=201 = 2^{0} into 2,147,483,648=2312\\,147\\,483\\,648 = 2^{31}.

예제2

  1. 예제 1

    입력
    5
    
    예상 출력
    5
    
  2. 예제 2

    입력
    2147483648
    
    예상 출력
    2