Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

sieve of eratosthenes python

# sieve of eratosthenes 
def SieveOfEratosthenes(n):
    prime = [True for i in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 1
    prime[0] = False
    prime[1] = False
    r = []
    for p in range(n + 1):
        if prime[p]:
            r.append(p)
    return r

n = int(input("Get primes in range of?- "))
listOfPrime = SieveOfEratosthenes(n)
count = 1
# print primes 1-100 then 101-200 etc. in different line
for i in listOfPrime:
    if i > 100 * count:
        count += 1
        print()
    print(i, end = " ")
Comment

sieve of eratosthenes python

# sieve of eratosthenes 
def SieveOfEratosthenes(n):
    prime = [True for i in range(n + 1)]
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 1
    prime[0] = False
    prime[1] = False
    r = []
    for p in range(n + 1):
        if prime[p]:
            r.append(p)
    return r

n = int(input("Get primes in range of?- "))
listOfPrime = SieveOfEratosthenes(n)
count = 1
# print primes 1-100 then 101-200 etc. in different line
for i in listOfPrime:
    if i > 100 * count:
        count += 1
        print()
    print(i, end = " ")
Comment

PREVIOUS NEXT
Code Example
Python :: import math sqrt python 
Python :: test split 
Python :: urllib3 python 
Python :: copy string python 
Python :: add system path python jupytre 
Python :: How to scale a pandas dataframe 
Python :: how to insert item last in list python 
Python :: select multiple columns in pandas dataframe 
Python :: find unique char in string python 
Python :: tkinter slider 
Python :: dataframe row print 
Python :: flask autherror 
Python :: drop column from dataframe 
Python :: random numbers python 
Python :: work with gzip 
Python :: find length of text file python 
Python :: python multiline string 
Python :: how to display percentage in pandas crosstab 
Python :: django error table already exists 
Python :: python add item multidimensional list 
Python :: datetime date from string 
Python :: extract tgz files in python 
Python :: # find out of the memory of the python object 
Python :: python function returns function 
Python :: python tkinter colored line 
Python :: how to make a distance function in python 
Python :: async sleep python 
Python :: read emails from gmail python 
Python :: k choose n python 
Python :: pyside 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =