Adding solutions to problems 389, 39 and 40