A statistical mechanics approach to the factorization problem