Cod sursa(job #635571)

Utilizator elfusFlorin Chirica elfus Data 19 noiembrie 2011 13:16:02
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.63 kb
#include <stdio.h>
#define MOD 10007

int FastPow (int A, int B)
{
    if (B == 0)
        return 1;
    int now = FastPow (A, B >> 1);
    if (B & 1)
        return ((long long)now * now * A) % MOD;
    else
        return (long long)now * now % MOD;
}

int main ()
{
    int N, M, K, P, T, sol;

    freopen ("matrice5.in", "r", stdin);
    freopen ("matrice5.out", "w", stdout);

    scanf ("%d", &T);
    while (T --)
    {
        scanf ("%d%d%d%d", &N, &M, &P, &K);
        sol = ((long long)FastPow (P, N * M) * FastPow (K, (N - 1) * (M - 1))) % MOD;
        printf ("%d\n", sol);
    }

    return 0;
}