Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
python code:
import math
sqrt=math.sqrt
def func(x):
m=int(sqrt(x)+1)
for i in range(2,m):
if x%i==0:
return 0
return 1
num=600851475143
n=sqrt(num)+1
n=int(n)
result=0
for i in range(2,n):
if num%i==0:
if func(i)==1:
result=i
print(result)
result : 6857
time: <1s
时间: 2024-12-28 16:12:44