The Gateway to Computer Science Excellence

0 votes

The following function computes an array $SPF$, where, for any integer $1 < i < 1000$, $SPF[i]$ is the smallest prime factor of $i$. For example, $SPF[6]$ is $2$, and $SPF[11]$ is $11$.

There are five missing parts in the following code, commented as $/* Blank */$. For each of them, copy the entire line with the comment and fill the blank appropriately in your answer sheet.

int SPF[1000]; void findSPF() { SPF[1] = 1; // Initializing SPF of every number to be itself for (int i = 2; i < 1000; i++) { _____; /* Blank 1 */ } // SPF of every even number is 2 for (int i = 4; i < 1000; i += 2) { SPF[i] = _____; /* Blank 2 */ } // For odd numbers, updating the SPFs of their multiples for (int i = _____; i * i < 1000; i++) { /* Blank 3 */ if (SPF[i] == i) { // No smaller factor of i found yet for (int j = _____; j < 1000; j+= i) { /* Blank 4 */ if (SPF[j] == j) { SPF[j] = _____; /* Blank 5 */ } } } } }

- All categories
- General Aptitude 1.9k
- Engineering Mathematics 7.5k
- Digital Logic 2.9k
- Programming and DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6.2k
- Compiler Design 2.1k
- Databases 4.1k
- CO and Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.5k
- Others 1.5k
- Admissions 595
- Exam Queries 576
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 17

50,645 questions

56,601 answers

195,852 comments

102,211 users