-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
33 lines (25 loc) · 1.1 KB
/
Copy pathgpt4_solution.py
File metadata and controls
33 lines (25 loc) · 1.1 KB
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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
# Precompute the fifth powers of digits 0-9
fifth_powers = [i ** 5 for i in range(10)]
# Determine the upper limit for checking numbers
# 9^5 = 59049, so for a 6-digit number, the maximum sum of fifth powers is 6 * 59049 = 354294
# Therefore, we only need to check numbers up to 354294
upper_limit = 6 * fifth_powers[9]
total_sum = 0
# Check each number from 2 to the upper limit
for number in range(2, upper_limit):
# Calculate the sum of the fifth powers of its digits
sum_of_powers = sum(fifth_powers[int(digit)] for digit in str(number))
# If the sum of the fifth powers equals the number, add it to the total sum
if sum_of_powers == number:
total_sum += number
return total_sum
# END - CODE GENERATED BY gpt4
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))