-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem48.py
49 lines (28 loc) · 1 KB
/
Problem48.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Code by @AmirMotefaker
# projecteuler.net
# https://projecteuler.net/problem=48
# Self powers
# Problem 48
# 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.
# Solution 1
import time
start_time = time.time() #Time at the start of program execution
solution = 0
for i in range(1, 1001):
solution += i**i
print (str(solution)[-10:]) # printing the last 10 digits
end_time = time.time() #Time at the end of execution
print ("Time of program execution:", (end_time - start_time)) # Time of program execution
# Solution 2
# import time
# start_time = time.time() #Time at the start of program execution
# def main():
# total = 0
# for i in range(1,1001):
# total += i**i
# print(str(total)[-10:])
# main()
# end_time = time.time() #Time at the end of execution
# print ("Time of program execution:", (end_time - start_time)) # Time of program execution
### Answer: 9110846700