Update Problem5.cpp

Removing Redundant loops.