Skip to content

Instantly share code, notes, and snippets.

@nspool
Created January 4, 2020 22:07
Show Gist options
  • Save nspool/2e534b11a03fef08c693d7238ef5710a to your computer and use it in GitHub Desktop.
Save nspool/2e534b11a03fef08c693d7238ef5710a to your computer and use it in GitHub Desktop.
Euler 3
s = 0
def fib(x,y):
if y < 4000000:
if y % 2 == 0:
global s
s = s + y
v = fib(y, x + y)
return v
else:
return 0
def largest_prime_factor(n):
# Make it odd (cheating!)
p = 775145
# check that it divides n
while p > 1:
if (n % p) == 0:
q = p
i = (q - 1) / 2
while q % i != 0:
i = i - 1
if i == 1:
print('return q')
return q
p = p - 2
print('return p')
return p
# def fmt(n):
n = 600851475143
# n = 13195
print(largest_prime_factor(n))
# print(fmt(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment