1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
coldgirl [10]
2 years ago
7

The Sieve of Eratosthenes is an elegant algorithm for finding all the prime numbers up to some limit n. The basic idea is to fir

st create a list of numbers from 2 to n. The first number is removed from the list, and announced as prime, and all multiples of this number is removed up to n are removed from the list. This process continues until the list is empty.
For example, if you wanted to find all the prime numbers up to 10, the list would contain 2, 3, 4, 5, 6, 7, 8, 9, 10. The 2 is removed and announced to be prime and 4, 6, 8, and 10 are removed since they are multiples of 2. That leaves 3, 5, 7, 9., repeat the process until the list is empty.
Write a program that prompts a user for n and then uses the sieve algorithm to find all the prime numbers less than or equal to n.
Computers and Technology
1 answer:
IRISSAK [1]2 years ago
4 0

Answer:

Check the explanation

Explanation:

#!usr/bin/python

#FileName: sieve_once_again.py

#Python Version: 2.6.2

#Author: Rahul Raj

#Sat May 15 11:41:21 2010 IST

 

fi=0 #flag index for scaling with big numbers..

n=input('Prime Number(>2) Upto:')

s=range(3,n,2)

def next_non_zero():

"To find the first non zero element of the list s"

global fi,s

while True:

if s[fi]:return s[fi]

fi+=1

def sieve():

primelist=[2]

limit=(s[-1]-3)/2

largest=s[-1]

while True:

m=next_non_zero()

fi=s.index(m)

if m**2>largest:

primelist+=[prime for prime in s if prime] #appending rest of the non zero numbers

break

ind=(m*(m-1)/2)+s.index(m)

primelist.append(m)

while ind<=limit:

s[ind]=0

ind+=m

s[s.index(m)]=0

#print primelist

print 'Number of Primes upto %d: %d'%(n,len(primelist))

if __name__=='__main__':

sieve()

You might be interested in
How do you determine which type of operating system that best supports your computer or mobile device?
kirill115 [55]
Run a compatibility check on your computer to check it or ask a tech professional what os they think would be compatible 
4 0
3 years ago
How many questions do you have to answer before you can use direct messages on Brainly?
steposvetlana [31]

Answer:

im pretty sure it 5

Explanation:

4 0
2 years ago
Read 2 more answers
"The ______ of an operational system that supports an organization includes policies, requirements, and conditional statements t
Serggg [28]

Answer:

decision logic

Explanation:. The decision logic of an operational system that supports an organization includes policies, requirements, and conditional statements that govern how the system works. These systems includes the following :

a) Order processing,

b)Pricing

c) Inventory control, and

d) Customer relationship management. And the traditional means of modifying the decision logic of information systems involves heavy interaction between business users and information technology (IT) analysts.

3 0
3 years ago
Write down the numbering system from base 2 to 200​
natka813 [3]

Answer:

So, 11001000 is the binary equivalent of decimal number 200 (Answer).

 

3 0
3 years ago
Hi can someone help me make a like a song for music Class pls I attached an example of what i need.
g100num [7]

Answer:

i dont really like music so sorry i cant help i hope someone can help you with this.

8 0
3 years ago
Other questions:
  • "Which of the following will help protect against a brute force attack?
    11·1 answer
  • Methods inherited from the base/super class can be overridden. This means changing their implementation; the original source cod
    5·1 answer
  • Suppose that a server sends four packets of audio data, in 15 seconds each. The first is sent by the server exactly at noon (12:
    14·1 answer
  • Label provides the code that executes if no case label is matched ​
    6·1 answer
  • Which person would be the best fit for a career in the Information Technology field?
    6·2 answers
  • Write a pseudocode statement that declares the variable total so it can hold integers. Initialize the variable with the value 0
    9·1 answer
  • PLZZZZ help will give brainlest
    5·1 answer
  • Please write a Java program to read movies.txt file. (It is in Modules under Chapter Code) Create your own movies.ser file from
    14·1 answer
  • Suppression of politically or socially unacceptable co
    5·1 answer
  • True or False? The background color block should be inserted after all the images are added.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!