simple recurrent formula

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from sympy import binomial_coefficients_list
def nth(n):
if n % 2 == 0:
return 1 + sum([4**i for i in xrange(n/2)])
else:
return 0
def phi(n):
cff = binomial_coefficients_list(n)
return sum([cf for (idx, cf) in enumerate(cff) if (len(cff) - 2*idx - 1) % 6 == 0])
maxx = 27
# Типа гипотеза
print [nth(n) for n in xrange(maxx)]
# Типа то, что получил гарантированно
print [phi(n) for n in xrange(maxx)]
# На выходе
#[1, 0, 2, 0, 6, 0, 22, 0, 86, 0, 342, 0, 1366, 0, 5462, 0, 21846, 0, 87382, 0, 349526, 0, 1398102, 0, 5592406, 0, 22369622]
#[1, 0, 2, 0, 6, 0, 22, 0, 86, 0, 342, 0, 1366, 0, 5462, 0, 21846, 0, 87382, 0, 349526, 0, 1398102, 0, 5592406, 0, 22369622]