3
votes
1answer
72 views

Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?

Project Euler problem 407: If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1. The largest value of a such that a2 mod 6 = a is 4. Let's call M(n) the largest value of a < n ...
0
votes
0answers
57 views

Bit array not working as fast as expected [closed]

I recently downloaded the bitarray module from here, for a faster prime sieve, but the results are dismal. from bitarray import bitarray from numpy import ones from timeit import timeit def ...
7
votes
1answer
216 views

Project Euler #3 - how inefficient is my code?

So I am essentially a complete newbie to programming, and have been attempting to learn Python by completing the Project Euler problems. I haven't gotten very far, and this is my code for problem #3 : ...
2
votes
2answers
142 views

Criticize my first Python module please

This is a Python module I have just finished writing which I plan to use at project Euler. Please let me know how I have done and what I could do to improve it. # This constant is more or less an ...
2
votes
1answer
72 views

Largest Prime Factor

I'm trying to learn Python by working my way through problems on the Project Euler website. I managed to solve problem #3, which is What is the largest prime factor of the number 600851475143 ? ...
4
votes
2answers
206 views

Any better way to solve Project Euler problem # 5

So, here's my attempt on Problem # 5 of Project Euler, which is looking quite clumpsy when seen first time. Is there any better way to solve this? Or any built-in library that already does some part ...
2
votes
1answer
87 views

Code review needed for my Prime factorization code

Below is the code for knowing all the prime factors of a number. I think there must be some better way of doing the same thing. Also, please tell me if there are some flaws in my code. def ...
0
votes
2answers
236 views

Functional prime factor generator

I have this prime factor generator for some number n. It returns list of all prime factors. In other words, product of the list equals n. def prime_factors_generate(n): a = [] prime_list = ...
3
votes
3answers
116 views

Naive prime finder, unexpected behavior in Python

I have verified that both of my following functions successfully find prime numbers. I was pretty sure the function called is_prime_new would be faster than is_prime_old; however, after benchmarking ...
4
votes
2answers
232 views

Improving runtime of prime generation

I just answered the question on project euler about finding circular primes below 1 million using python. My solution is below. I was able to reduce the running time of the solution from 9 seconds to ...
5
votes
3answers
3k views

Prime factorization of a number

I'm trying to learn Python through the excellent online book Dive Into Python 3. I have just finished chapter 2 about data types and felt like trying to write a program on my own. The program takes ...
4
votes
2answers
274 views

Euler 35 - python solution taking too long

Here is my solution for Project Euler 35. (Find the number of circular primes below 1,000,000. Circular meaning all rotations of the digits are prime, i.e. 197, 719, 971.) The code takes about 30 ...
1
vote
5answers
844 views

Sieve of Eratosthenes: making it quicker

I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
3
votes
1answer
199 views

Can anyone perhaps teach me how to further optimize this 'print up to the nth prime number' script?

I'm a 17 year old getting started with programming with the help of the Python programming language. I've been seeking to optimize this algorithm, perhaps by eliminating one of the loops, or with a ...