Implemented problem 31
Implemented problem 16