QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22781. ライフサイクル

Statistics

牛たちはそれぞれの識別札の番号の「ライフサイクル」を計算しています。

正の整数 $N$($1 \le N \le 9999$)、例えば 57 を取り、各桁を二乗して足します。$5^2+7^2$ により $25 + 49 = 74$ となります。結果の 74 に同じ操作をすると、列の次の数 65 が得られます。各項にこの操作を続けると、やがて列中のある数が再び現れます。

57 から始めると、最初に繰り返される数は 37 です:

$57, 74, 65, 61,$

その後、列は「ライフサイクル」に閉じ込められます:

$37, 58, 89, 145, 42, 20, 4, 16, 37, \ldots$

各桁を二乗ではなく三乗しても、列は同じような結末を迎えます。開始する正の整数と指数 $P$($1 \le P \le 5$)が与えられるので、ライフサイクルに入るまでの列の長さを計算するプログラムを作ってください。

入力

空白で区切られた 2 つの整数 $N$ と $P$ が 1 行に与えられます。

出力

ライフサイクルに入るまでの列の長さ。周期の最初の数は含めません。

入出力例

入力 1

57 2

出力 1

4

注記

出力の詳細

[これは列 $57, 74, 65, 61, 37, \ldots$ に対応します。37 は最初に繰り返される数です。]

問題作成者:Piele,2002

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.