Skip to content

Instantly share code, notes, and snippets.

View igorvanloo's full-sized avatar

Igor igorvanloo

View GitHub Profile
@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
@igorvanloo
igorvanloo / p46.py
Created July 25, 2021 03:34
Problem 46
def goldbachs(number):
for x in range(1, int(math.sqrt(number))+1):
temp_var = number - 2*(x**2)
if is_prime(temp_var) == True:
return True
return False
def compute():
count = 33
while True:
@igorvanloo
igorvanloo / p79.py
Created July 24, 2021 13:23
Problem 79
def all_numbers(alist):
nums = set()
for x in alist:
for y in x:
nums.add(y)
return list(nums)
def method1():
possible_numbers = (all_numbers(keys))
possible_passcode = list(itertools.permutations(possible_numbers))