Skip to content

Instantly share code, notes, and snippets.

@betaprojects
Last active September 11, 2020 21:06
Show Gist options
  • Save betaprojects/094906b1fdcbeb35a20bb6e68af2a9c7 to your computer and use it in GitHub Desktop.
Save betaprojects/094906b1fdcbeb35a20bb6e68af2a9c7 to your computer and use it in GitHub Desktop.
Project Euler & HackerRank problem 3 solution: Largest prime factor - solved using Python
n = int(input('The largest prime factor of '))
while n%2==0: n//= 2 # Remove all even factors
d = 3
while d*d <= n:
if n % d == 0:
n//= d
else:
d+= 2
print ("is", 2 if n==1 else n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment