Project Euler Number 3

 avatar
unknown
python
a year ago
589 B
5
Indexable
import time
from math import sqrt

start_time=time.time()

def prime_no(a):
    for i in range(2,a-1):
        if a%i ==0: 
            return False
    return True

def firstfact(a):
     factor=0
     for i in range(2,(int(sqrt(a))+1)):
        if prime_no(i):
            if a%i==0:
                factor=i
                return factor
                break
   
number_for_tree=600851475143
a=number_for_tree

while True:
    a=int(a/firstfact(a))
    if prime_no(a):
        print(a)
        break
         
print("%s seconds" % (time.time()-start_time))
Leave a Comment