Quantum chemistry without diagonalization: An extension of the Lanczos method to molecules and solids