22730_Generaterandomnumbers

2022-5-16 18:22| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-5-89506902334899-Problem List-采集的数据-后羿采集器.html

Pro.ID

22730

Title

Generate random numbers

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=22730

AC

15

Submit

15

Ratio

100.00%

时间&空间限制

  • Time Limit: 200/100 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    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 a0, which has a decimal representation of length at most n. We then multiply the value a0 by itself, add leading zeros until we get a decimal representation of length 2 × n and take the middle n digits to form ai. This process is repeated for each ai with i > 0. In this problem we use n = 4.

    Example 1: a0 = 5555 , a02 = 30858025 , a1 = 8580, ...

    Example 2: a0 = 1111 , a02 = 01234321 , a1 = 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 a0 how many different numbers are produced.

    输入

    The input contains several test cases. Each test case consists of one line containing a0 (0 < a0 < 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.

    输出

    Description

    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 a0, which has a decimal representation of length at most n. We then multiply the value a0 by itself, add leading zeros until we get a decimal representation of length 2 × n and take the middle n digits to form ai. This process is repeated for each ai with i > 0. In this problem we use n = 4.

    Example 1: a0 = 5555 , a02 = 30858025 , a1 = 8580, ...

    Example 2: a0 = 1111 , a02 = 01234321 , a1 = 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 a0 how many different numbers are produced.

    Input

    The input contains several test cases. Each test case consists of one line containing a0 (0 < a0 < 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

    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.

    Sample Input

    5555
    0815
    6239
    0

    Sample Output

    32
    17
    111

    Hint

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

    Source

    样例输入

    5555
    0815
    6239
    0

    样例输出

    32
    17
    111

    提示

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


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部