Fix condition in series.
Unnecessary variable p1 was deleted.
Calculate power of two on fly.