Skip to content

Instantly share code, notes, and snippets.

@melvinmt
Created September 13, 2013 08:41
Show Gist options
  • Save melvinmt/6548158 to your computer and use it in GitHub Desktop.
Save melvinmt/6548158 to your computer and use it in GitHub Desktop.
def is_prime(x):
if x < 2:
return False
if x == 2:
return True
if x % 2 == 0:
return False
i = 3
while i < x:
if x % i == 0:
return False
i += 2
return True
def generate_primes(limit):
i = 1
while i < limit:
i += 1
if not is_prime(i):
continue
yield i
def highest_prime_for(n):
primes = generate_primes(n)
current_prime = 2
for x in range(n):
if n % current_prime != 0:
current_prime = primes.next()
continue
n = n / current_prime
if is_prime(n):
return n
def main():
n = raw_input("Which number? ")
print "Highest prime factor for", n, "is", highest_prime_for(int(n))
main()
@AlexDT
Copy link

AlexDT commented Sep 13, 2013

oh ja en newline aan het eind van je bestand jonge, kom op melvin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment