No.3358 Fractional Part of the Reciprocal
Problem Statement
You are given as input a positive real number $X$ that can be represented as a finite decimal in base ten.
As long as $X$ remains positive, repeat the operation of replacing $X$ with the fractional part of $X^{-1}$.
Here, the fractional part of a real number $x$ is the value $x - \lfloor x \rfloor$ obtained by subtracting from $x$ the largest integer $\lfloor x \rfloor$ not exceeding $x$.
Find the number of times the operation is performed.
Input
The input is given from Standard Input in $1$ line in the following format:
- If $X$ is an integer, $X$ is given as a half-width integer in base ten.
- If $X$ is not an integer, $X$ is given as a half-width finite decimal in base ten, written without redundant trailing $0$s.
$X$
Constraints
The input satisfies the following constraints:
- $X$ is a real number satisfying $0 < X < 10^9$.
- $10^9 X$ is an integer.
Output
If the operation is performed only a finite number of times, print that number; if it is performed infinitely many times, print infty, in $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
1
Output
1
Initially, $X$ is given as $1$.
The $1$st operation replaces $X$ with $0$, the fractional part of $1^{-1} = 1$.
Since $X = 0$ now, no more operations are performed.
Sample 2
Input
1.5
Output
3
Initially, $X$ is given as $1.5$.
The $1$st operation replaces $X$ with $0.666 \cdots$, the fractional part of $1.5^{-1} = 0.666 \cdots$.
The $2$nd operation replaces $X$ with $0.5$, the fractional part of $(0.666 \cdots)^{-1} = 1.5$.
The $3$rd operation replaces $X$ with $0$, the fractional part of $0.5^{-1} = 2$.
Since $X = 0$ now, no more operations are performed.
Sample 3
Input
2
Output
2
Initially, $X$ is given as $2$.
The $1$st operation replaces $X$ with $0.5$, the fractional part of $2^{-1} = 0.5$.
The $2$nd operation replaces $X$ with $0$, the fractional part of $0.5^{-1} = 2$.
Since $X = 0$ now, no more operations are performed.
Sample 4
Input
999999999.999999999
Output
4
Initially, $X$ is given as $999999999.999999999$.
The $1$st operation replaces $X$ with $0.00000000100000000000000000100000000000000000100000 \cdots$, the fractional part of $999999999.999999999^{-1} = 0.00000000100000000000000000100000000000000000100000 \cdots$.
The $2$nd operation replaces $X$ with $0.999999999$, the fractional part of $(0.00000000100000000000000000100000000000000000100000 \cdots)^{-1} = 999999999.999999999$.
The $3$rd operation replaces $X$ with $0.00000000100000000100000000100000000100000000100000 \cdots$, the fractional part of $0.999999999^{-1} = 1.00000000100000000100000000100000000100000000100000 \cdots$.
The $4$th operation replaces $X$ with $0$, the fractional part of $(0.00000000100000000100000000100000000100000000100000 \cdots)^{-1} = 999999999$.
Since $X = 0$ now, no more operations are performed.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。