#include #define DIM 2 const int Mod = 10000; void copy_matrix(int d, long long A[][DIM], long long B[][DIM]) { int i, j; for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = A[i][j]; } void prod_matrix(int d, long long A[][DIM], long long B[][DIM], long long C[][DIM]) { int i, j, k; for (i = 0; i < d; i++) { for (j = 0; j < d; j++) { for (k = 0, C[i][j] = 0; k < d; k++) C[i][j] += A[i][k] * B[k][j] % Mod; C[i][j] %= Mod; } } } void pow_matrix(int d, long long A[][DIM], long long k, long long B[][DIM]) { int i, j; long long C[2][DIM][DIM], D[DIM][DIM]; copy_matrix(d, A, C[0]); for (i = 0; i < d; i++) for (j = 0; j < d; j++) B[i][j] = 0; for (i = 0; i < d; i++) B[i][i] = 1; for (i = 0, j = 1; k > 0; i ^= 1, j ^= 1, k >>= 1) { prod_matrix(d, C[i], C[i], C[j]); if (k % 2 == 1) { prod_matrix(d, B, C[i], D); copy_matrix(d, D, B); } } } void prod_matrix_vector(int d, long long A[][DIM], long long x[], long long y[]) { int i, j; for (i = 0; i < d; i++) { for (j = 0, y[i] = 0; j < d; j++) y[i] += A[i][j] * x[j] % Mod; y[i] %= Mod; } } int main() { int s; long long M, L; scanf("%d", &s); scanf("%lld", &M); scanf("%lld", &L); if (L == 0) { printf("%04d\n", s); fflush(stdout); return 0; } else if (M <= 1) { printf("0000\n"); fflush(stdout); return 0; } int i, j, p[61][10001]; long long A[DIM][DIM], B[DIM][DIM], x[DIM], y[DIM]; for (i = 1, p[0][0] = 0; i < 10000; i++) { A[0][0] = i; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; pow_matrix(DIM, A, M - 1, B); x[0] = 1; x[1] = 0; prod_matrix_vector(DIM, B, x, y); p[0][i] = y[0]; if (M % 2 != 0) { p[0][i]--; if (p[0][i] < 0) p[0][i]++; } } for (j = 1; j <= 60; j++) { for (i = 0; i < 10000; i++) { p[j][i] = p[j-1][p[j-1][i]]; } } for (j = 0; L > 0; j++, L >>= 1) { if ((L & 1) == 0) continue; s = p[j][s]; } printf("%04d\n", s); fflush(stdout); return 0; }