問題一覧 > 教育的問題

No.3358 Fractional Part of the Reciprocal

レベル : / AI推定難易度 : 500 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 46
作問者 : 👑 p-adic / テスター : yu23578
お気に入りにしたユーザー ProblemId : 12372 / 自分の提出
問題文最終更新日: 2025-09-17 21:11:19
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 488 小数誤差コンテスト (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。