# conditional probability throwing coins

We have two coins one of which is fair, turning heads and tails equally likely and the other biased, turning heads with probability $p$ and tails with probability $(1-p)$. We select at random one of the coins:

The selected coin is tossed repeatedly until it turns up heads $k$ times. Given that the coin is tossed $n$ times in total, what is the probability that the coin is biased?

I want to make sure my solution is correct. What sort of confuses me is that this is sort of a double conditional probability:

Denote by $P(B)$ the probability that the selected coin is biased.

$P(B|(n-tosses|k-heads))=\frac{P((n-tosses|k-heads)|B)P(B)}{P((n-tosses|k-heads)|B)P(B)+P((n-tosses|k-heads)|B^c)P(B^c)}$

$P((n-tosses|k-heads)|B)=\frac{P((n-tosses|k-heads)\cap B)}{P(B)}=\frac{P(n-tosses \cap k-heads\cap B)}{P( k-heads\cap B) P(B)}$

I know how to calculate the probabilities, i ust want to know if the formulas are correct.

You're over-complicating it- there's no need to frame the probability of getting $k$ heads in $n$ tosses as a conditional probability. Let $E$ represent the event of getting $k$ heads in $n$ tosses such that the last toss results in a head. Calculate the probability of $E$ for the $2$ cases: when the coin is unbiased, $P(E\ |\ B^c)$ and when it's biased, $P(E\ |\ B)$.
$$P(B\ |\ E) = \frac{P(E\ |\ B)P(B)}{P(E\ |\ B)P(B) + P(E\ |\ B^c)P(B^c)}$$