Destroying the spire
Time limit1sMemory limit512 MB
Given N, M, and a seed, compute the monster strength on floor N, a power tower of values g(k), modulo M.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Recursion
- Solved
- No attempts yet
Problem
Hyeongi often plays a game called Destroying the Spire. The player enters the spire at floor 1 and climbs one floor at a time to the top, defeating every monster on each floor. After clearing the spire, a new attempt brings different monsters.
When a new game starts, a seed (Seed) is generated at random. The seed determines the strength (Strength) of the monsters on each floor. The seed is a 10-character string made of letters A to Z, a to z, and digits 1 to 9 (0 is not used). To compute strength, each character of the seed is replaced with the integer value in the table below.
For example, when the seed is AB1z8DcdT4, the first character 'A' has the value 10. is the character at position counting from the left.
The monster strength on floor 1 is 1. For floor , the strength is computed as follows.
Find the strength of the monster on the top floor, floor , of a spire game with floors, modulo .
Input
The first line contains two integers and . ()
The second line contains . is a 10-character string made of letters A to Z, a to z, and digits 1 to 9.
Output
Print the strength of the monster on floor modulo on the first line.