Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def tribonacci(n):
- if n <= 0:
- return []
- sequence = [1, 1, 2]
- if n <= 3:
- return sequence[:n]
- for i in range(3, n):
- next_term = sequence[i - 1] + sequence[i - 2] + sequence[i - 3]
- sequence.append(next_term)
- return sequence
- n = int(input())
- tribonacci_sequence = tribonacci(n)
- print(" ".join(map(str, tribonacci_sequence)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement