Little X learned about the Cantor function from their Advanced Mathematics class. And he thinks it is interesting, so he wants to calculate this function.
The Cantor function is a function $C:[0,1] \rightarrow [0,1]$ that is defined as follows:
The Cantor function has several properties:
These properties make the Cantor function an important example in mathematical analysis and fractal geometry.
To calculate it for a specific value of $x$, you can follow these steps:
Input one line that cantains two integers $a$, $b$ ($1 \le a < b \le 1e18$), representing the value of $x = \frac{a}{b}$ for which Little X want to calculate the Cantor function.
Condition1: Given a fraction $ \frac{a}{b} = 0.eooo..._{(3)}$, where the digits in the repeating block are denoted by 'o'. For example, $\frac{13}{18} = 0.20111..._{(3)}$, where $e = 20$ and $o = 1$. It is guaranteed that $|e| + |o| \leq 60$ for the input $\frac{a}{b}$.
Condition2: Given a fraction $\frac{a}{b}$, the number of digits before the first digit '1' is $c$. For example, for $\frac{13}{18} = 0.20111..._{(3)}$, the number of digits before the first digit '1' is 2. It is guaranteed that $c \leq 60$ for the input $\frac{a}{b}$.
Note: For every input $\frac{x}{y}$, it is guaranteed to satisfy at least one of the prementioned conditions.
The output should only contain two integers $p$ and $q$($1 \le p \le q, gcd(b,q) = 1$), representing the fraction $\frac{p}{q}$ such that $C(\frac{a}{b}) = \frac{p}{q}$.
For the 2nd example, $\frac{3}{4} = 0.202020..._{(3)} \xrightarrow{Delete} 0.202020..._{(3)} \xrightarrow{Replace} 0.101010..._{(3)} \xrightarrow{Review} 0.101010..._{(2)} = \frac{2}{3}$.