Prompt and nonprompt J/psi production and nuclear modification in pPb collisions at root s(NN)=8.16 TeV