Python Forum
3rd problem from project Euler
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3rd problem from project Euler
#3
(Jun-05-2019, 10:06 AM)DeaD_EyE Wrote: You can improve the algorithm, if you define some primes. Here an example:
 def is_prime(n): primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 ] if n == 2: return True elif n % 2 == 0 or n <= 1: return False # speed up with known primes if n > 50 and any(n % p == 0 for p in primes): return False sqr = int(math.sqrt(n)) + 1 for divisor in range(3, sqr, 2): if n % divisor == 0: return False return True 
I got the point, but, don't you think it is too slow way to solve the problem? My programm is too slow for that big integer, and I guess I should think up about completely different algorithm to solve it, should i? Or i can somehow improve this one?
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 944 Oct-22-2023, 10:05 PM
Last Post: deanhystad
  Problem with importing python-telegram library into the project gandonio 1 1,709 Nov-01-2022, 02:19 AM
Last Post: deanhystad
  Calculate the Euler Number with more decimal places Pedroski55 10 4,803 Oct-31-2021, 04:45 AM
Last Post: Pedroski55
  IndexError in Project Euler attempt CRISPRmetoopls 3 2,415 Aug-10-2020, 10:00 AM
Last Post: perfringo
  graphing euler method rondo 1 2,571 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