def n(o, x): if x < 2: print o return if x % 3 - 2: n(o, x/3) for x in range(0,1000): n(x,x)