Prompt and nonprompt J/ψ production and nuclear modification in pPb collisions at s<inf>NN</inf>=8.16 TeV