Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@igorvanloo
igorvanloo / p618.py
Created July 28, 2021 18:29
Problem 618
def compute(limit):
d = [1] + [0] * limit
primes = eulerlib.primes(limit)
mod = 10**9
Fibonnaci_numbers = [2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368]
for p in primes:
for i in range(p,limit+1):
d[i] += (p*d[i-p] % mod)
@igorvanloo
igorvanloo / p82.py
Last active July 28, 2021 09:49
Problem 82
def compute():
matrix = [[131, 673, 234, 103,18],
[201, 96, 342, 965, 150],
[630, 803, 746, 422, 111],
[537, 699, 497, 121, 956],
[805, 732, 524, 37, 331]]
rows = len(matrix) #Number of rows
columns = len(matrix[0])#Number of columns
@igorvanloo
igorvanloo / p743.py
Created July 27, 2021 13:52
Problem 743
def A(k,n):
total = 0
f0 = 1
modulo = 1000000007
power = pow(2, n//k, modulo)
for a in range(0, n//k + 1):
total = (total + (f0 * pow(power, k-2*a, modulo))) % modulo
f0 = (f0*(k-2*a)*(k-2*a-1)) % modulo
f0 = (f0*pow((a+1)**2, -1, modulo)) % modulo
return total
@igorvanloo
igorvanloo / p700.py
Created July 26, 2021 12:55
Problem 700
def compute():
eulercoins = [1504170715041707]
current_eulercoin = 1504170715041707
inv = pow(1504170715041707, -1, 4503599627370517)
n = 2
while True:
number = 1504170715041707*n % 4503599627370517 #Search downwards
if number < current_eulercoin:
current_eulercoin = number
eulercoins.append(number)
@igorvanloo
igorvanloo / p659.py
Created July 26, 2021 04:18
Problem 659
def compute(limit):
f = [int(4*(x**2)+1) for x in range(limit+1)] #Initialise the list f
max_prime_factor = [0]*(limit+1) #Initialise the list max_prime_factor
for x in range(1,len(f)): #Go through f
div = f[x] #Initialise divisor
if div > 1: #Check if divisor > 1
curr1 = x % div
while curr1 <= limit: #while curr = x + k*f[x] < limit we continue
if f[curr1] % div == 0: #Check if f[x+k*f[x]] is divisible by f[x]
max_prime_factor[curr1] = max(max_prime_factor[curr1], div)
@igorvanloo
igorvanloo / p63.py
Created July 25, 2021 14:24
Problem 63
def compute():
count = []
for n in range(1,10):
for i in range(1,22):
if i == len(str(n**i)):
count.append(n**i)
return len(count)
#Used the following function to find the bounds for n
#n = 9 bound is 22 because 9^22
@igorvanloo
igorvanloo / p59.py
Created July 25, 2021 14:08
Problem 59
def compute(cipher):
possiblecodes = []
for x in range(97,123):
for y in range(97, 123):
for z in range(97,123):
password = chr(x) + chr(y) + chr(z)
count = 0
decrypt = []
for i in cipher:
temp = i^(ord(password[count % 3]))
@igorvanloo
igorvanloo / p52.py
Created July 25, 2021 08:01
Problem 52
def compute():
x = 100
while True:
count = 1
for i in range(2, 7):
if sorted(str(x)) != sorted(str(i*x)):
break
count += 1
if count == 6:
return x
@igorvanloo
igorvanloo / p49.py
Created July 25, 2021 04:52
Problem 49
def compute():
primes = sorted(list(set(list_primes(10000)) - set((list_primes(1000)))))
supercandidates = []
while len(primes) != 0:
curr = primes.pop()
candidates = [curr]
for y in primes:
if sorted(str(curr)) == sorted(str(y)):
candidates.append(y)
@igorvanloo
igorvanloo / p47.py
Last active July 25, 2021 05:20
Problem 47
def list_primality_modified(n):
result = [0] * (n + 1) #Initialize an array of length n+1
for i in range(2,int((n)) + 1): #We want to go all the way to the length instead of sqrt(n)
#to include all prime factors
if result[i] == 0: #If this value has not been marked yet, continue
for j in range(2 * i, len(result), i):
result[j] += 1 #Add all the prime factors
return result
#We will obtain a list where array[x] represents the number of prime factors of x,
#if array[x] = 0 then x is a prime