Given a positive integer n, return the n-th term of the following sequence.
The first four terms are N1=1, N2=2, N3=3 and N4=4. Every later term is the sum of the previous four terms:
Nk=Nk−1+Nk−2+Nk−3+Nk−4for k>4
Function Signature
def nth_term(n: int) -> int:
Rules
-
Terms are numbered from 1, so
n = 1
asks for
N1
.
-
Return the exact integer value of
Nn
.
Constraints
Examples
Input: n = 5
Output: 10
The fifth term is the first computed one: N5=N1+N2+N3+N4=1+2+3+4=10.
Input: n = 8
Output: 69
The sequence begins 1, 2, 3, 4, 10, 19, 36, 69, so the eighth term is 4 + 10 + 19 + 36 = 69.
Input: n = 3
Output: 3
For n from 1 to 4 the answer is one of the given starting terms, here N3=3.