~/algor $ cat problems/kombinatorika-aylana-boyash
Coloring a circle
Medium
1000 ms
128 MB
62%
A circle is divided into $n$ sectors numbered from $1$ to $n$ and arranged in order around the circle (sector $n$ is also adjacent to sector $1$). Each sector is painted in one of $k$ colors; adjacent sectors must have different colors. How many ways are there? Print the answer modulo $10^{9} + 7$.
Input
One line with two positive integers: $n$ and $k$.
Output
One integer — the number of ways modulo $10^{9} + 7$.
Note
$2 \le n \le 10^{18}$
$1 \le k \le 10^{9}$
Examples
Input #1
4 3
Output #1
18
Input #2
3 2
Output #2
0