ProgrammingVery hard
With fib(1) = fib(2) = 1, what is the largest n for which fib(n) fits in a signed 64-bit long long?
- A. 92
- B. 46
- C. 78
- D. 93
Correct answer: A. 92
fib(92) = 7540113804746346429 is below LLONG_MAX = 2^63 - 1, but fib(93) is about 1.22 x 10^19 and overflows. 93 is the limit for unsigned 64-bit, 46 for a signed 32-bit int, and 78 the last value a double holds exactly (below 2^53).
More C Programming questions
- 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?
- Growing a dynamic array by a fixed 1 element every time it fills (capacity + 1) costs what in the worst case for N pushes?