#P9748. Apple Removal Process

    ID: 22894 Type: Default 1000ms 256MiB

Apple Removal Process

Apple Removal Process

There are (n) apples on Little Y's desk, arranged in a row from left to right and numbered from (1) to (n). Every day, Little Bao, a friend of Little Y, removes some apples in the following way: she always starts from the first (leftmost) apple, and then, skipping one apple each time, she picks every alternate apple (i.e. she removes the apple at every odd position in the current row). After that, the remaining apples are rearranged in their original order to form a new row.

The task is to determine two things:

  1. The total number of days required to remove all the apples.
  2. The day on which the apple originally numbered (n) is removed.

The process can be mathematically described as follows:

  1. On day 1, all apples at odd positions ((1, 3, 5, \ldots)) are removed. If (n) is odd, then the apple numbered (n) is removed on day 1; if (n) is even, it survives.

  2. If an apple survives day (d) and it was originally at an even position, in the rearranged row its new position becomes its original position divided by 2. Thus, if (n) is even, let (f(n) = 1 + f(n/2)) be the day on which it is removed, with (f(1) = 1).

  3. The total number of days to remove all apples can be computed by repeatedly taking (\lfloor \frac{n}{2} \rfloor) until no apples are left. In other words, let the total days (T(n)) be defined as (T(n)=1+T(\lfloor n/2 \rfloor)) with (T(0)=0).

Your program should read the integer (n) as input and output two integers: the total number of days required and the day on which the apple numbered (n) is removed.

inputFormat

The input consists of a single line containing an integer (n) ((1 \leq n \leq 10^9)), which is the number of apples.

outputFormat

Output two integers separated by a space: the total number of days needed to remove all the apples and the day on which the apple originally numbered (n) is removed.

sample

1
1 1