Logic Building
# Take n
n = int(input("Enter number of terms: "))
# Generate Pell series
if n <= 0:
print("Invalid input")
elif n == 1:
print("0")
elif n == 2:
print("0 1")
else:
a, b = 0, 1
print(a, b, end=" ")
for i in range(2, n):
c = 2 * b + a
print(c, end=" ")
a, b = b, c
print()Output
Enter number of terms: 8 0 1 2 5 12 29 70 169
Pell series: P(n) = 2*P(n-1) + P(n-2).
Key Concepts:
- Start with 0, 1
- Each next = 2*previous + previous-1
- Special recurrence relation