This page is still under construction.

Parts of this page are still being built. What you see may change.

Last eight digits of a power tower

Time limit1sMemory limit256 MB

Summary
Given a and b, print the last eight digits of the b-level power tower of a, keeping leading zeros for large values.
Level

Hard8 of 10

Topics
Number theory, Math, Recursion
Solved
No attempts yet

Problem

For positive integers aa and bb, write the bb-th power tower of aa as a↑↑ba \uparrow\uparrow b. It is defined by

a↑↑1=aa \uparrow\uparrow 1 = a

a↑↑(k+1)=a(a↑↑k)a \uparrow\uparrow (k + 1) = a^{(a \uparrow\uparrow k)}

For example, 3↑↑2=33=273 \uparrow\uparrow 2 = 3^3 = 27 and 3↑↑3=327=76255974849873 \uparrow\uparrow 3 = 3^{27} = 7625597484987.

Find the last 8 digits of a↑↑ba \uparrow\uparrow b.

Input

The first line contains two positive integers aa and bb, separated by a space. (1≤a,b≤200001 \le a, b \le 20000)

Output

Print the last 8 digits of a↑↑ba \uparrow\uparrow b on one line.

If a↑↑ba \uparrow\uparrow b has 9 or more digits, print those last 8 digits exactly, including any zeros at the front of them. If a↑↑ba \uparrow\uparrow b has 8 or fewer digits, print the whole value without adding leading zeros.

Examples7

  1. Example 1

    Input
    3 3
    
    Expected output
    97484987
    
  2. Example 2

    Input
    1 20000
    
    Expected output
    1
    
  3. Example 3

    Input
    2 2
    
    Expected output
    4
    
  4. Example 4

    Input
    20000 1
    
    Expected output
    20000
    
  5. Example 5

    Input
    8 2
    
    Expected output
    16777216
    
  6. Example 6

    Input
    9 2
    
    Expected output
    87420489
    
  7. Example 7

    Input
    2 4
    
    Expected output
    65536