Possible Duplicate:
Recurrence Relations
How do I find the n:th number in the tribonacci series?
I need and algorithm fast enough for n up to 10^15.
Tribonacci numbers are defined as a(n) = a(n-1) + a(n-2) + a(n-3) with a(0)=a(1)=0, a(2)=1.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For any sequence with a linear recurrence, the matrix exponentiation algorithm works.
If e.g. the sequence has the recurrence
for
k >= 3and initial valuesa[0], a[1], a[2], you obtain the triple(a[n+2], a[n+1], a[n])by multiplyingThe matrix can be raised to the nth power using exponentiation by repeated squaring in
O(log n)steps.