PyPE solution to PE problem 63

Registered by Scott Armitage

PyPE solution to PE problem 63

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Scott Armitage
Completed by
Scott Armitage

Related branches

Sprints

Whiteboard

    ProjectEuler.net problem 63
    ===========================

    The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit
    number, 134217728=89, is a ninth power.

    How many n-digit positive integers exist which are also an nth power?

    Solution
    --------

    We wish to find all of the numbers of the form b**n where the length of the
    number is equal to n; in other words,

        10**(n-1) <= b**n < 10**n.

    The right-hand inequality gives us an upper bound for b; specifically, that
    b < 10, giving us the range b = 1..9.

    The left-hand inequality gives us an upper bound for n:

        n - 1 <= n * log10(b)
        n * ( 1 - log10(b) ) <= 1
        n <= 1 / ( 1 - log10(b) )

    Since n must be an integer, we can simply truncate (floor) the right-hand
    side of this expression to obtain the maximum value of n for a given base
    b. Since all of the solutions are of the form b**1, b**2, .. , b**n_max,
    then this maximum value for n is /also/ the number of integers that can
    be written as a power of base b.

    Now we simply take the sum of n_max(b) for b = 1..9.

    Answer
    ------

    49

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.