1. Engineering
  2. Computer Science
  3. just need the steps followed to change the following code...

Question: just need the steps followed to change the following code...

Question details

256 CHAPTER9 ARRAYS The above code can be modified to make it faster and save space. that. Your task is to do The first for loop that sets the values of isPrime to true wastes it to set isPrime [P) to true only for p - 2 and for all odd p >1. T Change care of even numbers: we know that the onty even prime is 2. Since we have taken care of even numbers, start the second for I and change the step from I to 2 ue wastes time. any1. This takes I. 3. Given the changes made in the previous two items, can the step in the 、 (inner) for loop be increased? How? third 4. Note that when we get to p, the numbers 2p, 3p,.., (p)p will already have ben crossed out on previous iterations. Make a change to the inner for loon utilize that fact to make the code a little faster. 5. We know that no even number except 2 is prime. To save space used to store rs are represented in the numbers, change the Sieve code so that only odd numbe is Prime array: ís Prime [k] s set to true if and only if 2k+1 İs prime.
indow Help 1 V/ Sieve of Ecatosthenes 3 public class Sieve İsprine[p] is set to true if and only if p is a prime 7e public static boolean[] markPrines(int n) boolean[] İsPrine-new boolean[n]; // all set to false by default İsPrine側. ísPrine[1)-false; // optional for (int í 2; İ < n; i++) // {false, false, true, true, 18 11 12 13 14 15 , true} İsPrine[1] true ; 16 for (int p 2; p<ni pt+) 17 18 19 20 21 if (isprime[p]) // ífisPrime[p] İs true for (int i-2p; ǐ < ni i +-p) isPrime[i]- false; 23 24 25 26 return isPrine; 27e public static void main(Stringt] args) 28 29 int n 120; boolean[] int count e; markPrines(n); 30 31 İsPr ine 32 for (int p -8; p< nj p++) 34 36 38 if (İsPrine[p]) System.out.print(p count++ System.out.println); 40 42 9 System.out.printin(count+ prines under n)i D Console 3 No consoles to display at this time.
Just need the steps followed to change the following code. Thanks
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution