project_euler/lib/num_fns.py

27 lines
505 B
Python
Raw Normal View History

2024-02-06 14:00:05 +00:00
import math
2024-02-06 13:25:34 +00:00
def isDivBy(num, denom):
return num % denom == 0
2024-02-06 13:45:15 +00:00
def fib(i):
2024-02-06 14:00:05 +00:00
if i == 1: return 1
elif i == 2: return 2
return fib(i - 1) + fib(i - 2)
def sieve(num):
prime = [True for i in range(num + 1)]
p = 2
while p * p <= num:
if prime[p] == True:
for i in range(p * p, num + 1, p):
prime[i] = False
p += 1
primes = []
for p in range(2, num + 1):
if prime[p]:
primes.append(p)
return primes