Q) The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
Solution: Python
==============
def isPrime(i):
x = 2
while x<=i/2:
if not i%x:
break
else:
x += 1
if not i%x:
return x,False
else:
return x,True
def primenos(num):
while True:
i,j = isPrime(num)
if not j:
num = num/i
elif j:
return num
print primenos(600851475143)
No comments:
Post a Comment