Heavy-quark production in p plus p and energy loss and flow of heavy quarks in Au plus Au collisions at root s(NN)=200 GeV