#P8588. Operations on Non-negative Integers

    ID: 21754 Type: Default 1000ms 256MiB

Operations on Non-negative Integers

Operations on Non-negative Integers

For a non-negative integer variable \( x \), we define one round of operations as follows:

  1. Increment \( x \) by 1.
  2. If \( x \) is a multiple of 3, then divide \( x \) by 3.

Given the initial values \( x \) and \( k \), perform \( k \) rounds of operations and output the final value of \( x \). Note that for each round, the division operation (if applicable) is applied immediately after the increment.

Note: The large test case is provided as Sample #3 in the input/output examples.

inputFormat

The input consists of a single line containing two space-separated numbers \( x \) and \( k \), where \( x \) is a non-negative integer and \( k \) is the number of rounds to perform.

Example:

5 3

outputFormat

Output a single integer — the value of \( x \) after performing \( k \) rounds of operations.

Example:

2

sample

1 1
2