Toric necklaces

A shop wants to commercialize a new kind of jewellery: toric necklaces! Given an infinite supply of kk different beads, a toric necklace is built by picking nmn \cdot m beads and placing them on an n×mn\times m grid. Then we join every pair of beads that are vertically adjacent with blue thread, and every pair of beads that are horizontally adjacent with red thread. Finally, we use blue thread to join the jj-th bead of the first row with the jj-th bead of the last row, and red thread to join the ii-th bead of the first column with the ii-th bead of the last column.

Here, we consider two toric necklaces equivalent if one can be obtained from the other by horizontal and/or vertical rotations. In other words, two necklaces defined by the matrices A[0n1,0m1]A[0\ldots n-1,0\ldots m-1] and B[0n1,0m1]B[0\ldots n-1,0\ldots m-1] are equivalent if there exist xx and yy such that A[i,j]=B[(i+x)modn,(j+y)modm]A[i,j] = B[(i+x) \bmod n, (j+y) \bmod m] for every ii and jj.

Given nn, mm and kk, can you compute the number of different toric necklaces?

Input

Input consists of several different cases, each one with nn, mm and kk, all between 1 and 10610^6.

Output

For every case, print the number of n×mn\times m toric necklaces that can be built with beads of kk different kinds, modulo 109+710^9 + 7.

Problem information

Author: Lander Ramos

Generation: 2026-01-25T10:30:40.031Z

© Jutge.org, 2006–2026.
https://jutge.org