Hyper operator a(n)b
<!-- MATH
$a{(n)}b = \left { \begin{array}{cc} b+1, & \mbox{if } n=0 \a, & \mbox{if } n=1, b=0 \0, & \mbox{if } n=2,b=0 \1, & \mbox{if } n \ge 3, b = 0 \a{(n-1)}(a{(n)}(b-1)) & \mbox{if } n \ge 1, b \ge 1, a \ge 0 \end{array} \right.$
-->
a(n)b =
WIDTH="20" HEIGHT="126" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-1.png"
ALT="$ \left\{\vphantom{ \begin{array}{cc} b+1, & \mbox{if } n=0 \\ a, & \mbox{if } ...
...n-1)}(a^{(n)}(b-1)) & \mbox{if } n \ge 1, b \ge 1, a \ge 0 \end{array} }\right.$">
WIDTH="330" HEIGHT="126" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-2.png"
ALT="$ \begin{array}{cc} b+1, & \mbox{if } n=0 \\ a, & \mbox{if } n=1, b=0 \\ 0, & ...
... \\ a^{(n-1)}(a^{(n)}(b-1)) & \mbox{if } n \ge 1, b \ge 1, a \ge 0 \end{array}$">
With some algebraic manipulations, it can be shown that the operators for n =
For values of n > 3
$a{(n)}b \bmod m$
-->
a(n)b mod m
The first line of input contains an integer T
$m \ n \ a \ b$
-->
m n a b
$0 \le n \le 10$
-->
0
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">n
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">10
$0 \le a, b \le 1000$
-->
0
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">a, b
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">1000
$1 \le m \le 10000$
-->
1
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">m
WIDTH="18" HEIGHT="31" ALIGN="MIDDLE" BORDER="0"
SRC="/ntujudge/problemdata/635-3.png"
ALT="$ \le$">10000
For each of the test cases, print the test case number followed by the value of <!-- MATH
$a{(n)}b \bmod m$
-->
a(n)b mod m
4
78 1 123 456
257 3 16 16
2008 4 8 3
1000 4 13 27
Case #1: 33
Case #2: 1
Case #3: 816
Case #4: 53
Migrated from old NTUJ.
ACM ICPC regional Jakarta site 2008
No. | Testdata Range | Score |
---|