ProgrammingVery hard
A sieve of Eratosthenes up to n = 100 marks composites by starting each prime p at p*p, and only for p*p <= n. How many marking operations are performed in total?
- A. 100
- B. 168
- C. 90
- D. 104
Correct answer: D. 104
Primes 2, 3, 5 and 7 mark 49, 31, 16 and 8 entries, respectively. 49 + 31 + 16 + 8 = 104.
More C Programming questions
- With fib(1) = fib(2) = 1, what is the largest n for which fib(n) fits in a signed 64-bit long long?
- A loop appends one character to a string with strcat(s, "x") for n = 10^5 times. Each strcat calls strlen on the whole string first. What…
- for (i = 0; i < strlen(s); i++) process(s[i]); with a string of length 5. How many times is strlen called?
- Which C code is correct and fast enough for finding whether a sorted array a of n = 2 x 10^5 ints has two elements summing to t?
- For N = 10^6 integers in the range 0 to 10^6, which sorting method is correct and fast enough?
- A queue is needed for 10^5 operations on an array. Which dequeue is correct and fast enough?