Max's Power Tower
InterviewTime limit2sMemory limit1024 MB
Given a right-associative power tower of n natural numbers, find its value modulo 3.
- Level
Medium4 of 10
- Topics
- Math, Number theory
- Solved
- No attempts yet
Problem
Max is a very spoiled dog. Recently he begged Katy for a set of toy cubes with numbers written on them. He played with them for a while, then got bored and started stacking them into a tall tower.
The tower has cubes, and each cube has a natural number written on it. Max wants to know the value of the power tower . He cannot keep large numbers in his head, so he wants the result modulo 3. Help Max.
Exponentiation is right-associative.
Input
The first line contains a natural number (). The next line contains natural numbers ().
Output
Print the value of .
Hint
In the second test case, .