Toric necklaces P26979


Statement
 

pdf   zip

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.

Public test cases
  • Input

    1 2 2
    1 2 3
    2 2 2
    2 3 3
    3 5 1
    4 6 2
    1 1 500
    10 20 30
    720680 33199 792347
    1000000 1000000 1000000
    

    Output

    3
    6
    7
    130
    1
    699600
    500
    798528669
    229776682
    320081768
    
  • Information
    Author
    Lander Ramos
    Language
    English
    Official solutions
    C++
    User solutions
    C++