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]
3 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]3 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
What is the most used gaming keyboard in 2022?
Mademuasel [1]

Answer:

Razer Huntsman v2 Analog

Explanation:

I have done some research on this before.

8 0
3 years ago
How do I get rid of the thing on top? It is driving me INSANE!!
Zinaida [17]
Try restarting your laptop?
7 0
3 years ago
You want to be able to identify the services running on a set of servers on your network. Which tool would best give you the inf
puteri [66]

Answer:

Vulnerability scanner

5 0
3 years ago
Two files named numbers1.txt and numbers2.txt both have an unknown number of lines, each line consisting of a single positive in
Reika [66]

Answer:

see explaination for program code

Explanation:

scalar_product = 0

li=[]

li2=[]

#reading numbers1.txt and numbers2.txt intoli and li2 respectively

with open('numbers1.txt') as n1, open('numbers2.txt') as n2:

for line1 in n1:

li.append(int(line1))

for line2 in n2:

li2.append(int(line2))

#storing min list size into variable l

a=len(li)

b=len(li2)

if a<b:

l=a

else:

l=b

#calculating scalar product

for i in range(l):

scalar_product=scalar_product+li[i]*li2[i]

print("scalar product is",scalar_product)

6 0
3 years ago
. A search engine is a way to
Sindrei [870]
<span>Option A, the search engine is the way to get information on the internet through a web browser, installed on an operating system of a computer. It is software that gathers all the information and stores it to accelerate the search for the users by entering the data of the desired information.</span>
8 0
4 years ago
Read 2 more answers
Other questions:
  • You have a large company, and it is important to your business that your employees' work is backed up regularly. Which network w
    7·2 answers
  • Choosing the “Quick Print” button will ____________.
    14·1 answer
  • If you know about 3D printers could you help me fix mine?
    8·1 answer
  • Technician A says underinflation of a tire causes excessive one-sided wear on one side of the tread. Technician B says overinfla
    11·2 answers
  • Which of the following apply to the definition of Wide Area Networks? Check all of the boxes that apply.
    7·2 answers
  • Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
    13·1 answer
  • As discussed in the video, parallax measurements allow us to calculate distances to stars for which parallax is detectable. Supp
    14·1 answer
  • The mutating-table error is raised when a trigger attempts to execute a. an INSERT, UPDATE, or DELETE while another user is upda
    10·1 answer
  • Write any three type of looping structure with syntax​
    13·1 answer
  • Computer science is a blank process
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!