ProgrammingVery hardCAT · MBA placement

The Fibonacci numbers F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) satisfy gcd(F(m), F(n)) = F(gcd(m, n)). The procedure below uses this identity to find gcd(F(12), F(18)): it computes g = gcd(12, 18) and then prints F(g). What is printed?

The Fibonacci numbers F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) satisfy gcd(F(m), F(n)) = F(gcd(m, n)). The procedure below uses this identity to find gcd(F(12), F(18)): it computes g = gcd(12, 18) and then prints F(g). What is printed?
g = gcd(12, 18)
compute F(g) by iteration from F(0) = 0, F(1) = 1
Print F(g)
  1. A. 5
  2. B. 8
  3. C. 13
  4. D. 30

Correct answer: B. 8

gcd(12,18) = 6 and F(6) = 8. Computing F(5) gives 5, F(7) gives 13, and adding the two indices gives 30.

More Pseudocode and Code Tracing questions

Exams that ask this topic