optimized  prob #5 to iterate through ceiling instead of n