Write a program called generateprimes

Assignment Help Basic Computer Science
Reference no: EM13307046

Generating Prime Numbers

The Sieve of Eratosthenes is an elegant algorithm for finding all of the prime numbers up to some limit n. The basic idea is to first create a list of numbers from 2 to n. The first number is removed from the list, and announced as a prime number, and all multiples of the number up to n are removed from the list. This process continues until the list is empty.

For example, if we wished to find all the primes up to 10, the list would originally contain [2, 3, 4, 5, 6, 7, 8, 9, 10]. The 2 is removed and announced to be prime. Then 4, 6, 8, and 10 are removed, since they are multiples of 2. That leaves [3, 5, 7, 9]. Repeating the process, 3 is announced as prime, and 9 is removed because it is a multiple of 9. That leaves [5, 7]. And so on.

Write a program called generatePrimes.py that prompts the user for a number n and outputs all the primes less than or equal to n. You must use the algorithm described above.

Reference no: EM13307046

Questions Cloud

A random process has a gaussian distribution function : A random process has a Gaussian distribution function
Calculate a 10% commission of an item price when sold : Enter a bid for an item and the bids are stored in an STL priority_queue object. This allows the highest bid to be at front of the queue.
Compute the force of friction acting on the block : A spring with constant k=30N/m is used to shoot a block (mass 1kg) across a frictional horizontal surface. what is the force of friction acting on the block
Design the typical elements of the roof and floor framing : The structure consists of a wood frame with plywood roof deck, wall sheathing and floor deck. general form of the building construction is to be determined by the designer.
Write a program called generateprimes : Write a program called generatePrimes.py that prompts the user for a number n and outputs all the primes less than or equal to n. You must use the algorithm described above.
How much power does the bulb dissipate : A one loop circuit is connected thus: A 3.0 V source, with the + side connected to a 10 ohm resistor, how much power does the bulb dissipate
Discuss the term scalability : Discuss the term scalability. What does it mean?Why is it an important network design goal?What are some challenges designers face when designing for scalability.
Find a piece of art-consider civic art : Find a piece of art. Consider civic art, sculpture, an image you have in your home, graffiti, street performance, or an art experience that you find engaging. Start by describing the work of art. Use terminology from the text. You may consider the fo..
Calculate the speed of the observer : A siren has a frequency of 875 Hz when it and an observer are both at rest. The observer then starts to move and finds that the frequency he hears is 1251 Hz. What is the speed of the observer

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Business uses networks-computers-support business functions

Think about a business you are familiar with, one which urilizes networks and computers to support business functions. Make a list of ten important, specific items like computers, disks.

  A fuel economy study was carried out

A Fuel economy study was carried out for five models of cars. each car was driven 100 miles, and then the model of the car and the number of gallons used were placed in a line of the file Mileage.txt. Table 7.22 shows the data for the entries of t..

  Describe the graphical coordinate system in java

Describe the graphical coordinate system in Java. Where is the origin? What units apply to the x,y coordinates.

  Explaining initial values of cache tags and cache lines

Assuming that the initial values of the cache tags and the cache lines are completely arbitrary, Also, show how the cache tags will change for each of the above steps. You should justify your answer.

  The three common security goals

1. Confidentiality, integrity, and availability are the three common security goals. Select at least three security vulnerabilities that could jeopardize and compromise a database. Classify each vulnerability with being technical, managerial,..

  Use css comments to document the css program

Create a css file named style.css to format index.htm and provide a basic layout. Use css comments to document the css program.

  Develop a c program

Develop a C program. The program should implement and test the following function: uint countOnes(uint hexNumber); The function will return the number of one bits in hexNumber.

  Produce algorithm pseudocode code flowchart for problem

Produce an algorithm, pseudocode code and flowchart for the following probelm: A customer in a store is purchasing five items. Design a program that ask for the price of each item, and then displays the subtotal of the sale, the amount of sales ta..

  In what ways do different types of seismic waves differ

In what ways do different types of seismic waves differ from waves on water.

  Create a 64mb encrypted file system

Write an instruction sheet for the user so that she can make the modi cations to her home machine so that she can access the le on the ash drive containing the encrypted le system.

  How many system calls can the computer execute per second

Suppose that a computer can execute 2 billion instructions/sec and that a system call takes 1000 instructions

  How can two cubical

how can two cubical (six sided) dice be labelled using numbers {0,1,2,3,4,5,6} so that when the two dice are thrown, the sum has a uniform probability distribution over the integers ( 1,2...12}.The same number can repeat more than once on a face of e..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd