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
ipn [44]
2 years ago
9

To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: 1. Create a list of consecutive i

ntegers from two to n: (2, 3, 4, ..., n), 2. Initially, let p equal 2, the first prime number, 3. While enumerating all multiples of p starting from p2, strike them off from the original list, 4. Find the first number remaining on the list after p (it's the next prime); let p equal this number, 5. Repeat steps 3 and 4 until p2 is greater than n. 6. All the remaining numbers in the list are prime.

Computers and Technology
1 answer:
natta225 [31]2 years ago
7 0

Answer:

I am writing a Python program:

def Eratosthenes(n):  

   primeNo = [True for i in range(n+1)]  # this is a boolean array

   p = 2  # the first prime number is initialized as 2

   while (p * p <= n):     # enumerates all multiples of p

       if (primeNo[p] == True):                

           for i in range(p * p, n+1, p):  #update multiples

               primeNo[i] = False

       p = p + 1        

   for p in range(2, n):   #display all the prime numbers

       if primeNo[p]:  

           print(p),    

def main():     #to take value of n from user and display prime numbers #less than or equal to n by calling Eratosthenes method

   n= int(input("Enter an integer n: "))

   print("The prime numbers less than or equal to",n, "are: ")  

   Eratosthenes(n)      

main()      

Explanation:

The program contains a Boolean type array primeNo that is initialized by True which means that any value i in prime array will be true if i is a prime otherwise it will be false. The while loop keeps enumerating all multiples of p starting from 2, and striking them off from the original array list and for loops keep updating the multiples. This process will continue till the p is greater than n.  The last for loop displays all the prime numbers less than or equal to n which is input by user. main() function prompts user to enter the value of integer n and then calls Eratosthenes() function to print all the prime numbers less than or equal to a given integer n.

   

You might be interested in
1. Answer the following questions: a. What are the different types of number system? Name them.​
BigorU [14]

Answer:

binary,decimal, hexadecimal and octal number system

5 0
2 years ago
One of the jobs of the webmaster are to create a website<br>true or false
Talja [164]

true is the correct answer

8 0
3 years ago
Read 2 more answers
Which presentation guideline helps people with vision disabilities?
Alina [70]
Providing audio with images
4 0
3 years ago
Read 2 more answers
What is the largest safety threat to the ISS?<br> Will give brainlest :)
bulgar [2K]

Answer:

The largest safety threat to the ISS are the micrometeorite and orbital debris (MMOD) fires, impacts and toxic spills. These pose the biggest threat to the ISS astronauts.

Explanation:

The debris is as a result of collisions. An observation revealed that once a certain mass is passed, collisions give rise to more debris.

Another report revealed that the station has about 55% chance of being hit by tiny space rocks over a 10-year period. They can protected by installing new impact-protecting panels to the exterior of the station.

ISS means International Satellite Station.

4 0
3 years ago
There was a thunderstorm in your area and the power went out.
Anna71 [15]

Answer:

A) The law requires that when I get to an intersection, I have to allow a right-of-way to the vehicles approaching from the right.

B) if there is an officer directing traffic, then I have to follow the directives of the officer.

Cheers!

8 0
3 years ago
Other questions:
  • A smart refrigerator can use _____ to detect when you are running low on milk, and then send a reminder to you on a wireless net
    14·1 answer
  • Put the following five steps in the order in which you would perform them to use the Paste Special function: ____. 1. Select and
    5·1 answer
  • How can I use the internet/social media to protect my identity?
    14·1 answer
  • HTTP is the protocol that governs communications between web servers and web clients (i.e. browsers). Part of the protocol inclu
    12·1 answer
  • Reading for subject content follows the same steps as reading for entertainment. True or false.
    10·2 answers
  • Nonverbal messages from the movie it​
    5·2 answers
  • Most operating systems perform these tasks.
    7·2 answers
  • Select the item that best represents technology transfer?
    8·1 answer
  • Which programming languages are the best choices for desktop applications? Select 3 options.
    8·2 answers
  • What profession do you prefer to have in the future? In what way could you make an impact on society using the Internet?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!