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?- A. 60
- B. 15
- C. 30
- 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
- Problem: How many 4-digit numbers (1000 to 9999) are divisible by 11? Run the code. python print(sum(1 for x in range(1000, 10000) if x %…
- Problem: How many integers in [1, 100] have decimal digits summing to exactly 10? Run the code. python print(sum(1 for x in range(1, 101)…
- Problem: What is the minimum number of bit flips needed to make the binary string '00110' non-decreasing (all 0s then all 1s)? Run the…
- Problem: How many pairs (i < j) of 'aabab' have s[i] = 'a' and s[j] = 'b'? Run the code. python s = 'aabab' print(sum(1 for i in…
- Problem: How many distinct products a[i] a[j] (i < j) does [1, 2, 3, 4] produce? Run the code. python from itertools import combinations…
- Problem: What is the smallest positive integer missing from [3, 4, -1, 1]? Run the code. python a = [3, 4, -1, 1] m = 1 while m in a: m +=…