Python/project_euler/problem_03/sol2.py

19 lines
364 B
Python
Raw Normal View History

2017-10-24 15:41:19 +00:00
'''
Problem:
The prime factors of 13195 are 5,7,13 and 29. What is the largest prime factor of a given number N?
e.g. for 10, largest prime factor = 5. For 17, largest prime factor = 17.
'''
2018-10-24 10:50:39 +00:00
from __future__ import print_function
2018-10-20 19:45:08 +00:00
n=int(input())
2017-10-24 15:41:19 +00:00
prime=1
i=2
while(i*i<=n):
while(n%i==0):
prime=i
n//=i
2017-10-24 15:41:19 +00:00
i+=1
if(n>1):
prime=n
print(prime)