replace some pow by explicit loops