-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler012.py
45 lines (37 loc) · 1.03 KB
/
Euler012.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
# ==============================================================================
# title : Euler012.py
# description : https://projecteuler.net/problem=12
# author : Marcel
# date : 2022-07-19
# version : 1.0
# python_version : 3.10.5
# ==============================================================================
import math
from time import *
def divisors(n):
i = 2
arr = [1, n]
# Runs until square of n
while i <= math.sqrt(n):
if (n % i == 0):
# If equal, only add one of them to array
if (n / i == i):
arr.append(i)
else:
# Otherwise add both
arr.append(i)
arr.append(int(n/i))
i = i + 1
# Return array with all divisors of n
return arr
def solve(maxDivisors):
k = 1
j = 2
while (len(divisors(k)) <= maxDivisors):
k = j + k
j += 1
print(k)
t1 = time()
solve(500)
t2 = time()
print('Running for: ', round(t2 - t1, 4), 'sec')