sieve-of-eratosthenes

Python finding Prime Numbers between any two numbers

Python finding Prime Numbers between any two numbers Question: I’m trying to find prime numbers between any two random numbers. Firstly, I have written the code like: m,n = map(int, raw_input().split()) for i in range(m, n+1): for j in range(2, i): if i%j == 0: break else: print i, Now for test case suppose I …

Total answers: 2

Factorizing a number in Python

Factorizing a number in Python Question: Here’s my code: def factorize(n): sieve = [True] * (n + 1) for x in range(2, int(len(sieve) ** 0.5) + 1): if sieve[x]: for i in range(x + x, len(sieve), x): sieve[i] = False lowerPrimes = i for i in range(2, len(sieve)) if sieve[i]] and (n % i == …

Total answers: 5

Sieve of Eratosthenes – Finding Primes Python

Sieve of Eratosthenes – Finding Primes Python Question: Just to clarify, this is not a homework problem 🙂 I wanted to find primes for a math application I am building & came across Sieve of Eratosthenes approach. I have written an implementation of it in Python. But it’s terribly slow. For say, if I want …

Total answers: 24