Data Structures & AlgorithmsVery hardICPC regional · number theory

Problem: What is the Pisano period of the Fibonacci sequence modulo 10 (the length after which (F(n), F(n+1)) mod 10 repeats (0, 1))? Run the code.

Problem: What is the Pisano period of the Fibonacci sequence modulo 10 (the length after which (F(n), F(n+1)) mod 10 repeats (0, 1))? Run the code.
x, y, p = 0, 1, 0
while True:
    x, y = y, (x + y) % 10
    p += 1
    if (x, y) == (0, 1):
        break
print(p)
What is printed?
  1. A. 60
  2. B. 15
  3. C. 30
  4. D. 20

Correct answer: A. 60

The Pisano period for modulus 10 is 60, a standard value. The period for 2 is 3 and for 5 is 20, and 60 is their lcm-based combination.

More Coding Interview Problems questions

Exams that ask this topic