-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path048-self-powers.py
More file actions
executable file
·22 lines (18 loc) · 853 Bytes
/
Copy path048-self-powers.py
File metadata and controls
executable file
·22 lines (18 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/python3
"""
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.
"""
# This code runs in 0.0103161334991 seconds.
import time
# This function determines the sum of the self powers of the first n, integers.
def sum_self_powers(n): # Accepts an integer, n, which serves as an upper limit.
sum = 0 # A variable to keep track of our sum.
for i in range(1, n + 1): # Iterate through each of the numbers in the series.
sum += i**i # Add the number's self power to the sum.
return sum # Return the final sum.
#print sum_self_powers(10)
s = time.time()
print(sum_self_powers(1000) % 10000000000) # The modulus strips off the last 10 digits.
f = time.time()
print(f - s)