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]
3 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]3 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 to set up a paper format in any type of Microsoft version ????
Mashcka [7]
Explain further what you mean by that.
7 0
4 years ago
Sometimes we write similar letters to different people. For example, you might write to your parents to tell them about your cla
OleMash [197]

?

?????????????????????

4 0
3 years ago
A presenter selects multimedia materials primarily based on their ability to
Kisachek [45]
A presenter selects multimedia materials primarily based on their ability to emphasize a point.
7 0
3 years ago
Read 2 more answers
What is the first phone ever made?
pickupchik [31]

Answer:

the Telephone

Explanation:

Before the invention of electromagnetic telephones, mechanical acoustic devices existed for transmitting speech and music over a greater distance greater than that of normal direct speech. The earliest mechanical telephones were based on sound transmission through pipes or other physical media.The acoustic tin can telephone, or "lovers' phone", has been known for centuries. It connects two diaphragms with a taut string or wire, which transmits sound by mechanical vibrations from one to the other along the wire (and not by a modulated electric current). The classic example is the children's toy made by connecting the bottoms of two paper cups, metal cans, or plastic bottles with tautly held string.Some of the earliest known experiments were conducted by the British physicist and polymath Robert Hooke from 1664 to 1685. An acoustic string phone made in 1667 is attributed to him.For a few years in the late 1800s, acoustic telephones were marketed commercially as a competitor to the electrical telephone. When the Bell telephone patents expired and many new telephone manufacturers began competing, acoustic telephone makers quickly went out of business. Their maximum range was very limited. An example of one such company was the Pulsion Telephone Supply Company created by Lemuel Mellett in Massachusetts, which designed its version in 1888 and deployed it on railroad right-of-ways.Additionally, speaking tubes have long been common, especially within buildings and aboard ships, and they are still in use today. The telephone emerged from the making and successive improvements of the electrical telegraph. In 1804, Spanish polymath and scientist Francisco Salva Campillo constructed an electrochemical telegraph.The first working telegraph was built by the English inventor Francis Ronalds in 1816 and used static electricity. An electromagnetic telegraph was created by Baron Schilling in 1832. Carl Friedrich Gauss and Wilhelm Weber built another electromagnetic telegraph in 1833 in Göttingen.At the University of Gottingen, the two have been working together in the field of magnetism. They built the first telegraph to connect the observatory and the Institute of physics, which was able to send eight words per minute.

3 0
3 years ago
What folder holds 32-bit programs installed in a 64-bit installation of windows?
raketka [301]
<span>C:\Program Files (x86) folder</span>
8 0
3 years ago
Other questions:
  • A quality assurance test for digital imaging receptors is to check for dark noise. What is the purpose of this test?
    8·1 answer
  • Your boss wants you to set up an authentication scheme in which employees will use smart cards to log in to the company network.
    15·1 answer
  • Susan is in charge of the inventory reports for her company.She will need to find specific inventory items as well as project in
    9·1 answer
  • HELP!!!<br> THIS HAPPENS EVERY TIME
    6·2 answers
  • Terry visits the website www.examplewebsite.org. What can you gather about the site from the domain?
    8·1 answer
  • Two things every professional PowerPoint presentation should have
    8·1 answer
  • G. What are handheld computers? Write its types.​
    7·1 answer
  • Describe ONE similarity and ONE difference between the use of lighting in candid and posed photography.
    15·1 answer
  • How do u type please help
    11·2 answers
  • What is the address space of a computer with a 64-bit address bus?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!