Is there a direct formula to calculate k This formula is used to calculate the probability that two nodes shared a key.
$P_{c}=1-\left(\frac{((P-k)!)^{2}}{((P-2k)!P!)}\right)$
where 
$P$ is the key pool.
$P_{c}$ is the probability that a shared key exists between two nodes. 
$k$ is the shared key. 
if $P = 10000$ and $P_{c}= 0.5$. Then $k\approx 83$ (I wrote a dummy code that tries the values of $k$) . 
Is there a direct formula to calculate $k$ (given $P$ and $P_{c}$)?. Thank you in advance. 
 A: Consider the equation as
$$1-P_c=\frac{((P-k)!)^2}{ (P-2 k)!\,P!}$$ Take logarithms of both sides and use Stirling approximation of the factorial
$$\log(x!)=x (\log (x)-1)+\frac{1}{2} \left(\log (2 \pi )+\log
   \left({x}\right)\right)+\frac{1}{12
   x}+O\left(\frac{1}{x^3}\right)$$ Use it for each term and continue with Taylor series for infinitely large values of $P$. This would give
$$\log(1-P_c)=-\frac{k^2}{P}+O\left(\frac{1}{P^2}\right)$$ Neglecting the higher order terms, then 
$$k=\sqrt{-P \,\log(1-P_c)}$$ Applied to you example, this would give $k=83.2555$ which is not too bad (I hope) since, working with real numbers, the solution would be $k=82.9112$.
You could have better approximations introducing the next term to get
 $$\log(1-P_c)=-\frac{k^2}{P}+\frac{(1-2 k) k^2}{2
   P^2}+O\left(\frac{1}{P^3}\right)$$ but this will require solving for $k$ the cubic equation
$$2k^3+(2P-1)k^2+2P^2 \log(1-P_c)=0$$ which could be quite tedious. If you want to polish a little, use one iteration of Newton method starting with $k_0=\sqrt{-P \,\log(1-P_c)}$ and get
$$k_1=k_0-\frac{2k_0^3+(2P-1)k_0^2+2P^2 \log(1-P_c) }{6k_0^2+2(2P-1)k_0 }$$ For your case, $k_1=82.9152$.
Edit
We can have a better approximation using a few tricks.
Taking  the series to $O\left(\frac{1}{P^3}\right)$ as given above, making $P=\frac 1x$, building the simplest Padé approximant at $x=0$ and back to $P$, we can end with 
$$\log(1-P_c)=\frac{2 k^2}{2 k-2 P-1}$$ which gives
$$k=\frac{1}{2} \left(\log (1-P_c)+\sqrt{\log (1-P_c) (\log (1-P_c)-4 P-2)}\right)$$  For your case, this would give  $k=82.9117$ while the exact solution is $k=82.9112$.
