Add and Reverse
시간 제한1초메모리 제한1024 MB
0에서 시작해 주어진 32비트 n에 도달하는 최소 연산 횟수를 구한다. 각 연산은 1 더하기(2^32 모듈로) 또는 32비트 뒤집기 중 하나다.
문제
Consider a non-negative integer stored in bits of memory: where each bit can take two values and 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 -st bit and -th bit, swap -th bit and first bit, , swap -th bit and -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 ?
The increasing by one is carried out modulo , which means that, if the current number is equal to , increasing it by one produces a zero.
입력
The only line contains an integer ().
출력
Print one integer: the minimum possible number of operations required to transform a zero to the given integer .
힌트
In the first example, the fastest way to get a 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 into .