Project Euler Problem #188!

November 19th, 2009
by Serinox

Problem #188 says:

The hyperexponentiation or tetration of a number a by a positive integer b, denoted by a↑↑b or ^(b)a, is recursively defined by: a↑↑1 = a, a↑↑(k+1) = a^((a↑↑k)). Thus we have e.g. 3↑↑2 = 3^(3) = 27, hence 3↑↑3 = 3^(27) = 7625597484987 and 3↑↑4 is roughly 10^(3.6383346400240996*10^12). Find the last 8 digits of 1777↑↑1855.

This problem rather basic when you think about it mathematically. And even simpler once you realize that python has a built in modulo parameter to its pow() function. Making this whole problem rather simple. And with a bit of poking around one realizes that you don’t have to go through the whole loop as the value we’re looking for appears in the first 20 loops through the program.
Anyway, Solution is in python (2.6).

def Tetrate(Base,Tetrate,Modulo):
    Value = 1
    while Tetrate:
        Value = pow(Base,Value,10**Modulo)
        Tetrate = Tetrate - 1
    return Value

print "Answer : ", Tetrate(1777,1855,8)

Tags: , ,
Posted in Project Euler | Comments (0)