Consider $f$: $H\times K\rightarrow HK$ where $(h,k)\mapsto hk$, which elements go to $e$? $hk=e\iff h=k^{-1}\implies h\in H\cap K$. Once $h$ is chosen $k$ is $h^{-1}$. So there are $H\cap K$.
Notice if $(h,k)$ maps to $g$ then for every $l\in H\cap K$ $(hl,l^{-1}k)$ goes to $l$, so there are at least $H\cap K$ elements that go to $g$. Now suppose $(h_1,k_1)$ maps to $g$. Then $h_1k_1=hk\implies h_1=hkk_1^{-1}$ and $k_1=h_1^{-1}hk$ and $h^{-1}h_1=kk_1^{-1}$
So let $l=kk_1^{-1}$, then $l^{-1}=k_1k^{-1}=h^{-1}{h_1}$. So that
$(h_1,k_1)=(hl,l^{-1}k)$. so $(h_1,k_1)$ is of the intial form, hence there are $H\cap K$ elements that map to $g$ for each $g$. This tells us $|HK|=\frac{|H|\times |K|}{|H|\cap |K|}$.