-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
39 lines (32 loc) · 1.21 KB
/
Copy pathgpt4_solution.py
File metadata and controls
39 lines (32 loc) · 1.21 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
34
35
36
37
38
39
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def get_proper_divisors_sum(n):
total = 1
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
total += i
if i != n // i:
total += n // i
return total
def is_abundant(n):
return get_proper_divisors_sum(n) > n
limit = 28123
abundant_numbers = [i for i in range(12, limit + 1) if is_abundant(i)]
can_be_written_as_abundant_sum = [False] * (limit + 1)
for i in range(len(abundant_numbers)):
for j in range(i, len(abundant_numbers)):
sum_abundant = abundant_numbers[i] + abundant_numbers[j]
if sum_abundant <= limit:
can_be_written_as_abundant_sum[sum_abundant] = True
else:
break
total_sum = sum(i for i in range(1, limit + 1) if not can_be_written_as_abundant_sum[i])
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}))