Update Problem9.cpp

Making the program slightly more effective.