Add solution to problem #5, and a bit of refactor of solution to problem #3

Added solution to problem #5
Refactored the problem #3 solution because the factorization method can be reused. So I've mode it out from problem def.