Solution for problem 40
Solution for problem 41