Last Digits
InterviewTime limit2sMemory limit128 MB
For each test case, print the last n digits (with leading zeros) of the power tower of height i with base b.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Divide and conquer, Recursion
- Solved
- No attempts yet
Problem
Raising a number to repeated powers can produce a very large value.
You are given integers , , and . The function is defined by
so is a power tower of height with base . Write a program that finds the last digits of .
Input
The input consists of several test cases. Each test case consists of three lines: the first line contains (), the second line contains (), and the third line contains (). A single line containing follows the last test case and marks the end of input.
Output
For each test case, print the last digits of on its own line. If has fewer than digits, pad it with leading zeros so that exactly digits are printed.