21143_Eventuallyperiodicsequence

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

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

Pro.ID

21143

Title

Eventually periodic sequence

Title链接

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

AC

0

Submit

70

Ratio

0.00%

时间&空间限制

  • Time Limit: 1000/500 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Given is a function f: 0..N --> 0..N for a non-negative N and a non-negative integer nN. One can construct an infinite sequence F = f 1(n), f 2(n), ... f k(n) ... , where f k(n) is defined recursively as follows: f 1(n) = f(n) and f k+1(n) = f(f k(n)).

    It is easy to see that each such sequence F is eventually periodic, that is periodic from some point onwards, e.g 1, 2, 7, 5, 4, 6, 5, 4, 6, 5, 4, 6 ... . Given non-negative integer N ≤ 11000000 , nN and f, you are to compute the period of sequence F.

    输入

    Each line of input contains N, n and the a description of f in postfix notation, also known as Reverse Polish Notation (RPN). The operands are either unsigned integer constants or N or the variable x. Only binary operands are allowed: + (addition), * (multiplication) and % (modulo, i.e. remainder of integer division). Operands and operators are separated by whitespace. The operand % occurs exactly once in a function and it is the last (rightmost, or topmost if you wish) operator and its second operand is always N whose value is read from input. The following function:

    2 x * 7 + N %

    is the RPN rendition of the more familiar infix (2*x+7)%N. All input lines are shorter than 100 characters. The last line of input has N equal 0 and should not be processed.

    输出

    Description

    Given is a function f: 0..N --> 0..N for a non-negative N and a non-negative integer nN. One can construct an infinite sequence F = f 1(n), f 2(n), ... f k(n) ... , where f k(n) is defined recursively as follows: f 1(n) = f(n) and f k+1(n) = f(f k(n)).

    It is easy to see that each such sequence F is eventually periodic, that is periodic from some point onwards, e.g 1, 2, 7, 5, 4, 6, 5, 4, 6, 5, 4, 6 ... . Given non-negative integer N ≤ 11000000 , nN and f, you are to compute the period of sequence F.

    Input

    Each line of input contains N, n and the a description of f in postfix notation, also known as Reverse Polish Notation (RPN). The operands are either unsigned integer constants or N or the variable x. Only binary operands are allowed: + (addition), * (multiplication) and % (modulo, i.e. remainder of integer division). Operands and operators are separated by whitespace. The operand % occurs exactly once in a function and it is the last (rightmost, or topmost if you wish) operator and its second operand is always N whose value is read from input. The following function:

    2 x * 7 + N %

    is the RPN rendition of the more familiar infix (2*x+7)%N. All input lines are shorter than 100 characters. The last line of input has N equal 0 and should not be processed.

    Output

    For each line of input, output one line with one integer number, the period of F corresponding to the data given in the input line.

    Sample Input

    10 1 x N %
    11 1 x x 1 + * N %
    1728 1 x x 1 + * x 2 + * N %
    1728 1 x x 1 + x 2 + * * N %
    100003 1 x x 123 + * x 12345 + * N %
    0 0 0 N %

    Sample Output

    1
    3
    6
    6
    369

    Source

    样例输入

    10 1 x N %
    11 1 x x 1 + * N %
    1728 1 x x 1 + * x 2 + * N %
    1728 1 x x 1 + x 2 + * * N %
    100003 1 x x 123 + * x 12345 + * N %
    0 0 0 N %

    样例输出

    1
    3
    6
    6
    369

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部