Problem3
This commit is contained in:
parent
f7973c0719
commit
4599d7be12
@ -1,9 +1,26 @@
|
||||
import math
|
||||
|
||||
def isDivBy(num, denom):
|
||||
return num % denom == 0
|
||||
|
||||
def fib(i):
|
||||
if i == 1:
|
||||
return 1
|
||||
elif i == 2:
|
||||
return 2
|
||||
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
|
||||
|
14
src/problem3.py
Normal file
14
src/problem3.py
Normal file
@ -0,0 +1,14 @@
|
||||
import math
|
||||
import sys
|
||||
sys.path.append("lib")
|
||||
from num_fns import sieve, isDivBy
|
||||
|
||||
target = 600851475143
|
||||
|
||||
primes = sieve(math.floor(math.sqrt(target)))
|
||||
primes.reverse()
|
||||
|
||||
for i in primes:
|
||||
if isDivBy(target, i):
|
||||
print(i)
|
||||
break
|
Loading…
Reference in New Issue
Block a user