QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#3121. Generate random numbers

Statistics

John von Neumann suggested in 1946 a method to create a sequence of pseudo-random numbers. His idea is known as the "middle-square"-method and works as follows: We choose an initial value $a_0$, which has a decimal representation of length at most $n$. We then multiply the value $a_0$ by itself, add leading zeros until we get a decimal representation of length $2 × n$ and take the middle $n$ digits to form $a_i$. This process is repeated for each $a_i$ with $i>0$. In this problem we use $n = 4$.

Example 1: $a_0=5555$, $a_0^2=30858025$, $a_1=8580$,...

Example 2: $a_0=1111$, $a_0^2=01234321$, $a_1=2343$,...

Unfortunately, this random number generator is not very good. When started with an initial value it does not produce all other numbers with the same number of digits.

Your task is to check for a given initial value $a_0$ how many different numbers are produced.

Input Specification

The input contains several test cases. Each test case consists of one line containing $a_0$ ($0 < a_0 < 10000$). Numbers are possibly padded with leading zeros such that each number consists of exactly 4 digits. The input is terminated with a line containing the value 0.

Output Specification

For each test case, print a line containing the number of different values $a_i$ produced by this random number generator when started with the given value $a_0$. Note that $a_0$ should also be counted.

Sample Input

5555
0815
6239
0

Sample Output

32
17
111

Note that the third test case has the maximum number of different values among all possible inputs.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.