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
umka21 [38]
2 years ago
8

Prime numbers can be generated by an algorithm known as the Sieve of Eratosthenes. The algorithm for this procedure is presented

here. Write a program called primes.js that implements this algorithm. Have the program find and display all the prime numbers up to n = 150.
Sieve of Eratosthenes Algorithm
To Display All Prime Numbers Between 1 and n
Step 1: We need to start with all the numbers representing the range of numbers that are possible candidate primes. So, create an array of consecutive integers from 2 to n: (2,3,4,..n). I wouldn't hand-code this. I would use a loop to populate the array.
Step 2: At each step we select the smallest number and remove all it's multiples. So we'll start with an outer loop that goes from 2 to n. initially, let p equal 2, the first prime number.
Step 3: In an inner loop we need to iterate over all the numbers that are multiples of p, i.e for 2, that's 2,4,6,8 etc. Each time, setting it's value to false in the original array.
Step 4: Find the first number greater than p in the list that is not marked False. If there was no such number, stop. Otherwise, let p now equal this number( which is the next prime), and repeat from step 3.
When the algorithm terminates, all the numbers in the list that are not marked False are prime
Example: Let us take an example when n = 50. So we need to print all print numbers smaller than or equal to 50. We create list of all numbers from 2 to 50.
2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
Computers and Technology
1 answer:
Sidana [21]2 years ago
4 0

Answer:

const MAXNR=150;

let candidates = {};

for(let i=2; i<=MAXNR; i++) {

   candidates[i] = true;

}

for(let p=2; p <= MAXNR; p++) {

   if (candidates[p]) {

       process.stdout.write(`${p} `);

       // Now flag all multiples of p as false

       i=2;

       while(p*i <= MAXNR) {

           candidates[p*i] = false;

           i++;

       }

   }

}

You might be interested in
Password cracking is a technique used to extract user’s password of application/files without the knowledge of the legitimate us
Vlada [557]

Answer:

Rule based Attack.

Explanation:

                    As password cracking is a technique used to extract user’s password of application/files without the knowledge of the legitimate user. The attacker can use Rule Based Attack to find the password and to intrude or compromise the network and systems.

                    This is like a programming language to generate the password. This involves functions to modify, cut, edit and extend the generally used terms by the user.

5 0
3 years ago
Which is a potential disadvantage of emerging technologies? A. increased spread of misinformation due to advanced communication
Sergio039 [100]

Answer: I believe it’s D.

Explanation: Less developed countries may not be able to afford the new technology, while more developed ones will be able to do so. Meaning the less developed countries will most likely not change.

8 0
3 years ago
¿Cuántos megabytes (MB) de capacidad tiene una memoria USB de 16 GB? el que me diga por que le doy una coronita
-Dominant- [34]

Answer:

16,384MB

Explanation:

1GB contiene 1024MB de capacidad. Si multiplicamos esto por 16 veemos que 16GB es igual a 16,384MB. Este seria el espacio exacto, aunque se dice que 1GB tiene 1000MB. Eso es por que la palabra Giga significa x1000 y el numero binario entero mas cercano a 1000 es 1024. Entonces los ingenieros usan este numero para representar la cantidad de espacio en un GB que tambien seria 2^{10}

7 0
2 years ago
In your Pest Busters game, how does Player 2 move the Ship 2 object?
Nuetrik [128]

Answer:

The answer is A.

Explanation:

7 0
3 years ago
What report shows the percentage of traffic that previously visited a website?
lyudmila [28]

Answer:

New vs returning report under the Behaviour shows the percentage of traffic that has visited your site before. The “New vs Returning” report breaks out acquisition, behavior, and conversion goal metrics for new and returning users.

Explanation:

4 0
2 years ago
Other questions:
  • An effective team would never have​
    9·1 answer
  • ROE: what does this represent (in plain terms)? In what range would this number typically be? What type of person/position would
    11·1 answer
  • Discuss a situation in which you might want to use a floating-point number with a fractional part for a loop control variable. W
    5·1 answer
  • Working for the Internal Revenue Service is a career in public safety. A. True B. False
    14·1 answer
  • PLEASE ANSWER THIS IM IN A QUIZ
    15·2 answers
  • Understanding the link between education and your desired career is an integral part of your career _______.
    7·2 answers
  • What was the effect of the norman conquest on the language of britain?
    11·1 answer
  • Your task is to identify three or more ways that big data is being collected on a regular basis, including one data collection m
    9·1 answer
  • Sometimes we care about the order of a list, and need to reorder the items according to a condition (alphabetical, numerical, et
    11·2 answers
  • 7.2 code practice edhesive. I need help!!
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!