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
A person you respect who offers you advice and assistance is known as a(n) _____.
Archy [21]
This would be a mentor-D. They role is to mentor or guide you with advice or assistance. A role model is a similar answer in that they respect you, but they might not offer advice or assistance which makes it incorrect.
7 0
2 years ago
What is the term for an element on a Webpage that contains data and procedures for how that item will react when activated
dezoksy [38]

Answer:

It is an object.  And this is because an object has the data and procedures that defines how it is going to react when it is going to be activated. The data is the details about the object, and it explains what the object actually is. And the procedures are the details of the functions that the particular objects can perform. Like for a hospital, data can be mentioning list of medication services they provide, and procedure can be like registering for any medication service, the complete process.

Explanation:

The answer is self explanatory.  

6 0
2 years ago
TQ Automation<br> What is Robotic Process Automation (RPA)?
tamaranim1 [39]

Answer:

RPA or Robotic Process Automation allows organizations to automate tasks which human beings were doing across any applications and systems. The purpose of RPA is to transfer the execution of the process from humans to robots.

5 0
1 year ago
A program that will accept the ages of girls and boys and calculate the total and average age​
Firdavs [7]

Answer:..

hmmm...... i dont any programs that can do that

8 0
2 years ago
Decribe the advantages of using emails compared with physical faxing ?
fredd [130]

Answer:

email is SO much faster

Explanation:

6 0
2 years ago
Other questions:
  • Using the syntax in section 2.3, write a command delete_all_rights (p, q, s). this command causes p to delete all rights the sub
    13·1 answer
  • Your computer is crashing on a regular basis. Which of the following is an operation available to the user that should help rese
    6·2 answers
  • Xavier would like to change the sort options for his contacts. In which tab will he find the Arrangement command group?
    6·1 answer
  • A ______ is an exact duplication of the hard drive, including data files, system files, and settings, application files, and the
    15·1 answer
  • Use the _______ to add a line or circle to your presentation.
    8·1 answer
  • I need help!! I decided to go back to college this year and am taking Intro to Logic and Programming. I have an assignment due t
    5·1 answer
  • The cafeteria offers a discount card for sale that entitles you, during a certain period, to a free meal whenever you have bough
    13·1 answer
  • PLEASE HELP ME!!!
    13·1 answer
  • Write an algorithm (in pseudocode) for the following Scenario.
    7·1 answer
  • Suppose that you have the following definitions:
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!