Nontrivial solutions for a class of nonresonance problems and applications to nonlinear differential equations