Advertisement
RaFiN_

DZY Loves Fibonacci Numbers,CF - 446C

Jun 24th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. //codeforces - DZY Loves Fibonacci Numbers
  2. Btw:
  3.  
  4. We can do this without matrix multiplication:
  5.  
  6. 1) F(a, b, k) = a * fk - 2 + b * fk - 1 -- k-th element of general Fibonacii sequences starting with a, b, where fi — i-th Fibonacci numbers (starting from 1, 1).
  7.  
  8. 2) sum of first k members of general Fibonacci sequence Fi equals to Fk + 2 - F2.
  9.  
  10. So we only need to precalculate Fibonacci numbers.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement