forked from Xctrunner/pe_class
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
33 lines (30 loc) · 906 Bytes
/
utils.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
import math
def gen_primes(upper_limit):
bool_list = [True for _ in range(upper_limit)]
bool_list[0] = False
root = math.floor(math.sqrt(upper_limit))
for i in range(2, root + 1):
if bool_list[i - 1]:
square_list = [i ** 2 + x * i for x in range(upper_limit // i)]
for j in square_list:
if j - 1 < len(bool_list):
bool_list[j - 1] = False
prime_list = []
for x in range(len(bool_list)):
if bool_list[x]:
prime_list.append(x + 1)
return prime_list
def gen_fib(upper_limit):
fib_1 = 1
fib_2 = 1
fib_list = [fib_1, fib_2]
fib_result = 0
while True:
fib_result = fib_1 + fib_2
if fib_result > upper_limit:
break
else:
fib_list.append(fib_result)
fib_1 = fib_2
fib_2 = fib_result
return fib_list