/ OPS / 题库 /

Generate random numbers

Generate random numbers

#描述#
<p>
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 <b><i>a<sub>0</sub></i></b>, which has a decimal representation of
length at most <b><i>n</i></b>. We then multiply the value
<b><i>a<sub>0</sub></i></b> by itself, add leading zeros until we get a decimal
representation of length <b><i>2 &times n</i></b> and take the middle
<b><i>n</i></b> digits to form <b><i>a<sub>i</sub></i></b>. This process is
repeated for each <b><i>a<sub>i</sub></i></b> with <b><i>i>0</i></b>.
In this problem we use <b><i>n = 4</i></b>.
</p>
<p>
Example 1: <b><i>a<sub>0</sub></i></b>=5555,
<b><i>a<sub>0</sub><sup>2</sup></i></b>=30858025,

<b><i>a<sub>1</sub></i></b>=8580,...
</p>
<p>
Example 2: <b><i>a<sub>0</sub></i></b>=1111,
<b><i>a<sub>0</sub><sup>2</sup></i></b>=01234321,

<b><i>a<sub>1</sub></i></b>=2343,...
</p>
<p>
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.
</p>
<p>
Your task is to check for a given initial value <b><i>a<sub>0</sub></i></b>
how many different numbers are produced.
</p>

#格式#
##输入格式##
The input contains several test cases. Each test case consists of one line containing a0 (0 &lt a0 &lt 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.

##输出格式##
For each test case, print a line containing the number of different values ai produced by this random number generator when started with the given value a0. Note that a0 should also be counted.

#样例1#
##样例输入1##

5555
0815
6239
0

##样例输出1##

32
17
111

#限制#
1000ms
32768KB

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

#来源#

信息

ID
1795
难度
5
分类
category1 点击显示
标签
递交数
0
已通过
0
通过率
?
上传者