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$).

الإدخال

سطر واحد يحتوي على عددين صحيحين $N$ و$P$ يفصل بينهما فراغ.

الإخراج

طول التسلسل حتى يدخل دورة حياة، دون احتساب أول عدد في الدورة.

أمثلة

الإدخال 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.