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
Your firm's management team will expect a variety of reports from you and your team.
maxonik [38]

Answer:true

Explanation:they are your management and want you to tell them when you have completed a task or if something happens

7 0
3 years ago
Describe how an operating system interacts with the computer.
enyata [817]
The user requests an application to run by making a system call to get it started
6 0
3 years ago
Read 2 more answers
Display all 3-digit automorphic no.s.<br>Guys I need help!!!!!!<br>I WILL GIVE THE BRAINLIEST ❤️​
pshichka [43]

Answer:

hope my answer helps

Explanation:

Automorphic Number

Given a number N, the task is to check whether the number is Automorphic number or not. A number is called Automorphic number if and only if its square ends in the same digits as the number itself.

Examples :

Input : N = 76

Output : Automorphic

Explanation: As 76*76 = 5776

Input : N = 25

Output : Automorphic

As 25*25 = 625

Input : N = 7

Output : Not Automorphic

As 7*7 = 49

8 0
2 years ago
Read 2 more answers
I have a problem with a task using scipy.optimize.minimize execution through the following methods: CG, BFG, Newton-CG, L-BFGS-B
Scilla [17]

Answer:

Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

3 0
2 years ago
I have a class named Counter. In this class I have a synchronized method called countRange(). This method prints out a count in
lesya [120]

Answer:

Following are the code to this question:

Counter T = new Counter(1, 100); //creating Counter class object and call its parameterized constructor        

Thread T1 = new Thread(new Runnable()  //creating Thread object T1.

{            

   public void run() //define run method

   {                

       T.countRange(); //call countRange method    

   }          

});    

Thread T2 = new Thread(new Runnable()  //creating another object "T2" of Thread.

{            

   public void run() //define run method

   {                

       T.countRange();           //call countRange method

   }      

});    

T1.start(); //start Thread T1    

T2.start(); //start Thread T2    

Explanation:

Description of the above code as follows:

  • In the given code, inside the main method the Counter class object "T" is created, that calls its parameterized constructor, which accepts two integer value that is "1 and 100".  
  • In the next step, thread class object T1 and T2, is created, which uses run method, in which it called the countRange method inside the method a for loop is declared that prints value between parameter value.  
  • In the last step, the start method is called, which uses the run method to call countRange method.  
  • For full program code please find the attachment.

6 0
3 years ago
Other questions:
  • In a social networking site your personal information is listed under your?
    12·2 answers
  • There are several factors that can substantially affect the consumer search process. Match the factor with an example of how the
    5·1 answer
  • What acronym describes networked devices that contain microcomputers but are not thought of as computing devices, such as refrig
    9·1 answer
  • When specifying keywords to conduct an internet search, which of the following parts of speech will be the most useful??
    6·1 answer
  • A single-user database system automatically ensures ____ of the database, because only one transaction is executed at a time.
    13·1 answer
  • How do u delete a post on brainly
    7·1 answer
  • ¿Qué aspectos de impacto medioambiental e impacto social tienen relación con la poca disminución de los residuos? Es para hoy.
    13·1 answer
  • 8.6 Code Practice: Question 2
    7·1 answer
  • The term information technology was first used what year?
    15·2 answers
  • question 1 scenario 1, question 1-5 you’ve just started a new job as a data analyst. you’re working for a midsized pharmacy chai
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!