嵇爾的吐槽

#没事画轮子的嵇尔不定期的(W)碎(E)碎(B)念(B)和(L)吐(O)槽(G)

Problem 63 Powerful digit counts 2019-11-13 08:30:00

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

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

def digit(number):
    return len(str(number))

s = 0
for p in range(1, 100):
    l = []
    for i in range(1, 100):
        result = pow(i, p)
        if digit(result) < p:
            continue
        if digit(result) > p:
            break
        l.append(result)
    s += len(l)
print(s)
评论共