The ore condition for polynomial and power series rings