Problem of the day
You are given ‘N’ = 5, Here we know 0th, 1st and 2nd Tribonacci numbers are 0, 1 and 1 respectively. Therefore we can calculate the 3rd number as 0 + 1 + 1 = 2 and 4th number as 1 + 1 + 2 = 4 and 5th number as 1 + 2 + 4 = 7. Hence the answer is 7.
Can you solve it in logarithmic time?
The first input line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ representing Tribonacci number to find.
For each test case, print a single integer, representing the ‘N’th Tribonacci Number.
Print a separate line for each test case.
1 ≤ T ≤10
0 ≤ N ≤ 10^5
Time Limit: 1 sec
You do not need to print anything. It has already been taken care of. Just implement the given function.
2
5
2
7
1
For the first test case, ‘N’ = 5, Here we know 0th, 1st and 2nd Tribonacci numbers are 0, 1 and 1 respectively. Therefore we can calculate the 3rd number as 0 + 1 + 1 = 2 and 4th number as 1 + 1 + 2 = 4 and 5th number as 1 + 2 + 4 = 7. Hence the answer is 7.
For the second test case, ‘N’ = 2, Here, the second number in the Tribonacci sequence is already defined as 1. Hence the answer is 1.
2
0
9
0
81