Python Forum
3rd problem from project Euler
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3rd problem from project Euler
#1
The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?
-
I have written a programm for solving this problem, it easily displays prime factors of 13195, but once I insert a bigger number (like 600851475143), a programm goes into an infinite loop, it returns neither error, nor answer. Please help, where is the problem in code?

My code:

import math
a = []
b = range(1,600851475143)

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0 or n <= 1:
        return False

    sqr = int(math.sqrt(n)) + 1

    for divisor in range(3, sqr, 2):
        if n % divisor == 0:
            return False
    return True

b = (filter(is_prime,b))

for i in b:
    if 600851475143 % i == 0:
        a.append(i)
    else:
        pass
print (a)
print("The largest prime factory is",a[-1::])
Reply


Messages In This Thread
3rd problem from project Euler - by Richard_SS - Jun-05-2019, 09:57 AM
RE: 3rd problem from project Euler - by DeaD_EyE - Jun-05-2019, 10:06 AM
RE: 3rd problem from project Euler - by Richard_SS - Jun-05-2019, 10:51 AM
RE: 3rd problem from project Euler - by perfringo - Jun-05-2019, 10:56 AM
RE: 3rd problem from project Euler - by Richard_SS - Jun-05-2019, 12:13 PM
RE: 3rd problem from project Euler - by heiner55 - Jun-05-2019, 01:55 PM
RE: 3rd problem from project Euler - by DeaD_EyE - Jun-05-2019, 02:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  dynamic variable name declaration in OOP style project problem jacksfrustration 3 824 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Problem with importing python-telegram library into the project gandonio 1 1,612 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  Calculate the Euler Number with more decimal places Pedroski55 10 4,569 Oct-31-2021, 04:45 AM
Last Post: Pedroski55
  IndexError in Project Euler attempt CRISPRmetoopls 3 2,343 Aug-10-2020, 10:00 AM
Last Post: perfringo
  graphing euler method rondo 1 2,524 May-03-2019, 01:03 AM
Last Post: scidam

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020