code for computing P(T=k)