Great Pow!
Time limit10sMemory limit64 MB
Compute the tower of k+1 copies of a modulo a+1, where a is minus one so only the parity of the upper tower matters.
- Level
Medium5 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
Write the power as .
Then define and for .
Given and , compute , the value of the tower built from copies of :
The tower is evaluated from the top down. For , note that , and the value you need is the latter.
Input
The first line contains and separated by a space. (, )
Output
Print modulo . The value itself can be enormous, so only the remainder is printed.
Hint
, so print 65536 modulo 3, which is 1.