Solution (source code)

= Solution

Write every element as $a^kb^l$ with $k\in\{0,1\}$. The action of this element on $M=\mathbb Z$ is multiplication by $(-1)^k$. A direct check of the four possibilities for the two exponents of $a$ shows
$$
\phi(xy)=\phi(x)+x\phi(y),
$$
so $\phi$ is a <crossed homomorphism> and hence a <one-cocycle>.

It cannot be principal: if $\phi(g)=gm-m$ for some $m\in\mathbb Z$, then at $g=a$ one would have
$$
1=\phi(a)=a m-m=-2m,
$$
which is impossible in the <integers>. Thus $[\phi]\ne0$ and
$$
\boxed{H^1(D_n,M)\ne0}.
$$