Three-Step Sequence
Tribonacci is like Fibonacci, but each new number is the sum of the previous three. The sequence starts with T(0) = 0, T(1) = 1, and T(2) = 1. Given n, return T(n) using the rule T(n+3) = T(n) + T(n+1) + T(n+2).
Примеры
Ввод
4Вывод
4Ввод
25Вывод
1389537Ввод
0Вывод
0Нужно реализовать
def tribonacci(n: int) -> int:
Теги
dpmath
Prisijunkite, kad matytumėte pateikimų istoriją
PrisijungtiPrisijunkite, kad naudotumėte DI mentorių
PrisijungtiVisible tests
1
Input
4Expected
42
Input
25Expected
13895373
Input
0Expected
04
Input
1Expected
15
Input
2Expected
16
Input
-100Expected
1Focus radio
Paused · SomaFM · Fluid