P8588 『JROI-8』Thunderstorm Special Operations Division

Background

![1663764044201.png](https://img-kysic-1258722770.file.myqcloud.com/639b5f084b6aa779f0a90253f9eef153/b2f5e91db29b9.png) > "Angels do not have vacations."\ > "Ah, again... It is better not to push yourself too hard." **Reprint authorization has been obtained.**

Description

For a **non-negative integer** variable $x$, define one round of operations as follows: 1. Increase $x$ by $1$. 2. If $x$ is a multiple of $3$, divide $x$ by $3$. Given the initial $x$ and $k$, find the value of $x$ after $k$ rounds of operations. **Note: The large sample is not provided as an attached file. Instead, it is placed directly in Sample #3 of the Input/Output Samples.**

Input Format

One line with two non-negative integers $x, k$.

Output Format

One line with one positive integer, representing the value of $x$ after $k$ rounds of operations.

Explanation/Hint

[Sample Explanation] For Sample 1, the change process of $x$ is as follows: $1\rightarrow 2\rightarrow (3\rightarrow 1)\rightarrow 2$. The part in parentheses represents one operation. [Constraints and Notes] For all testdata, $0\leq x, k\leq 10^{18}$. **In particular, in test points $1\sim 2$, $k\leq 0$ is equivalent to $k=0$, and similarly for $x$ in $3\sim 4$.** | Test Point ID | Score | $x\leq$ | $k\leq$ | | -----------: | -----------: | -----------: | -----------: | | $1\sim 2$ | $20$ | $5$ | $0$ | | $3\sim 4$ | $20$ | $0$ | $10^{18}$ | | $5\sim 6$ | $20$ | $10^{18}$ | $10^6$ | | $7 \sim 10$ | $40$ | $10^{18}$ | $10^{18}$ | Translated by ChatGPT 5