Largest prime factor : Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?
http://projecteuler.net/problem=3
Answer: 6857
Python Code
import math
def largestPrimeFactor():
numb = input("Enter the number:")
pf = 1
def checkPrime(numb):
prime = True
for i in range(int(math.sqrt(numb))):
i = i+2
if numb%i == 0:
prime = False
break
if numb == 2:
return True
else:
return prime
for i in range(int(math.sqrt(numb))):
i = i+2
if checkPrime(i) == True and numb % i == 0:
print i
pf = i
print "Largest Prime factor of",numb,"is:",pf
largestPrimeFactor()
No comments:
Post a Comment