Reputation: 11
I'm trying to solve Problem 3 from this site https://projecteuler.net/problem=3 and it is call like this: ''The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? '' Why , when I trying run my code with large numbers (more, than 1000000) - it is print on screen nothng ? How can I solve this problem and solve this task?
I have some correct working code, that is work with small input argument ( like 13195. But, when I trying to take the answer with large argument, like 600851475143 and run this code, it is print nothng.
def is_it_prime(x): # function check: is it number a prime or not and return True or False?
if x != 1:
i = int(x/2)
else:
i = 1 # x == 1 It is a simple case, where is argument - it is a prime number
while i != 1:
if x % i == 0: # This number isn't prime
return False
i -= 1
return True # Done! We find largest prime number
def largest_prime(x): # function check argument on whole divide availible
i = int(x/2)
while True:
if x % i == 0: # argument have whole divide
if is_it_prime(i) == True:
break
i -=1
return i # It is the largest prime factor
print(largest_prime(600851475143))
--------------------------------------------------------
>>>
Upvotes: 0
Views: 28
Reputation:
**How to determine if a number is prime
A computer can be used to test extremely large numbers to see if they are prime. But, because there is no limit to how large a natural number can be, there is always a point where testing in this manner becomes too great a task even for the most powerful supercomputers.**
https://whatis.techtarget.com/definition/prime-number
Upvotes: 1