#include int p[60004]; int root(int n) { if (p[n] != n) p[n] = root(p[n]); return p[n]; } void uni(int a, int b) { a = root(a); b = root(b); p[a] = b; return; } int v[10][10]; int h, w; int g(int k) { int i, j, res = 0; for (i = 0; i < h; i++) for (j = 0; j < w; j++) res = k * res + v[i][j]; return res; } int f(int k) { int i, j, l, ll; int max = 1; for (i = 0; i < h; i++) for (j = 0; j < w; j++) max *= k; for (i = 0; i < max; i++) p[i] = i; int vv[10][10], ii, jj; for (l = 0; l < max; l++) { ll = l; for (i = h - 1; i >= 0; i--) { for (j = w - 1; j >= 0; j--) { v[i][j] = ll % k; ll /= k; } } for (i = 0; i <= h; i++) { for (j = 0; j <= w; j++) { uni(l, g(k)); for (ii = 0; ii < h; ii++) for (jj = 0; jj < w; jj++) vv[ii][jj] = v[ii][(jj + 1) % w]; for (ii = 0; ii < h; ii++) for (jj = 0; jj < w; jj++) v[ii][jj] = vv[ii][jj]; } for (ii = 0; ii < h; ii++) for (jj = 0; jj < w; jj++) vv[ii][jj] = v[(ii + 1) % h][jj]; for (ii = 0; ii < h; ii++) for (jj = 0; jj < w; jj++) v[ii][jj] = vv[ii][jj]; } } int ans = 0; for (i = 0; i < max; i++) if (root(i) == i) ans++; return ans; } int main() { int k; scanf("%d %d %d", &h, &w, &k); int ans; if (k == 1) ans = f(1); else if (k == 2) ans = f(2) - 2 * f(1); else ans = f(3) - 3 * f(2) + 3 * f(1); printf("%d\n", ans); return 0; }