About 140,000 results
Open links in new tab
  1. efficiently finding prime numbers in python - Stack Overflow

    Sep 28, 2017 · here is my code: def findPrimes(): prime=True c=0 n=1 while n<14: n=n+1 for i in range(1,n): if n%i==0: prime=False if prime==Tru...

  2. Is there a Python library to list primes? - Stack Overflow

    May 23, 2017 · Given an arbitrary integer N, the only way to find the next prime after N is to iterate through N+1 to the unknown prime P testing for primality. Testing for primality is very cheap, …

  3. python - Fastest way to list all primes below N - Stack Overflow

    Jan 15, 2010 · Nonetheless this is my suggestion for a pure python prime sieve, based on omitting the multiples of 2, 3 and 5 by using appropriate steps while processing the sieve …

  4. Print series of prime numbers in python - Stack Overflow

    May 30, 2020 · The best way to solve the above problem would be to use the "Miller Rabin Primality Test" algorithm. It uses a probabilistic approach to find if a number is prime or not. …

  5. Simple prime number generator in Python - Stack Overflow

    Mar 18, 2019 · import math import itertools def create_prime_iterator(rfrom, rto): """Create iterator of prime numbers in range [rfrom, rto]""" prefix = [2] if rfrom < 3 and rto > 1 else [] # include 2 if …

  6. how to find a prime number function in python - Stack Overflow

    using your code, and focusing on code structure: def is_prime(x): # function contents must be indented if x == 0: return False elif x == 1: return False # your base cases need to check X, not …

  7. Python Finding Prime Factors - Stack Overflow

    This question was the first link that popped up when I googled "python prime factorization".As pointed out by @quangpn88, this algorithm is wrong (!) for perfect squares such as n = 4, 9, …

  8. primes - isPrime Function for Python Language - Stack Overflow

    Mar 8, 2013 · Consider the prime number 5003: print is_prime(5003) Prints: 5 11 17 23 29 35 41 47 53 59 65 True The line r = int(n**0.5) evaluates to 70 (the square root of 5003 is …

  9. python - Program to find the nth prime number - Stack Overflow

    Feb 4, 2017 · Here I am checking for each prime number using all(num%i!=0 for i in range(2,num)) checking its remainder not equal to zero so if it is true for that range (starting …

  10. How to find prime numbers in python - Stack Overflow

    Jun 25, 2020 · Neither of your example count_primes() functions actually counts primes -- they simply print odd primes. Let's implement a working version of your trial division code, not using …

Refresh