当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3284:Eventually periodic sequence

题目描述

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 , n ≤ N 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.

输出解释

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.

输入样例
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

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3284

最后修改于 2020-10-29T06:57:43+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536