이경수 선생님의 수학실험실

Problem 48(Self powers) 본문

Project Euler

Problem 48(Self powers)

(이경수) 2019. 8. 16. 17:03

Problem 48(Self powers)

The series, \(1^{1}+ 2^{2}+ 3^{3}+ ... + 10^{10}= 10405071317\).

Find the last ten digits of the series, \(1^{1}+ 2^{2}+ 3^{3}+ ... + 1000^{1000}\).

 

In Python:

import time

def selfpower(n):
    product = 1
    for i in range(1, n + 1):
        product = (product * n) % (10 ** 10)
    return product

result = 0
for i in range(1, 1000):
    result += selfpower(i)
    result = result % (10 ** 10)
print(result)

Run time: 0.15167498588562012 seconds

 

Solution: 9110846700

Comments