Cod sursa(job #2092301)

Utilizator inquisitorAnders inquisitor Data 21 decembrie 2017 15:21:48
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>

long long T, N, M, P, K;

long long expo(long long A, long long B)
{
    long long result = 1;

    while(B)
    {
        if(B & 1) result = (result * A) % 10007;
        A = (A * A) % 10007;
        B >>= 1;
    }

    return result;
}

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

    scanf("%lld", &T);

    while(T--)
    {
        scanf("%lld %lld %lld %lld", &N, &M, &P, &K);

        printf("%lld\n", (expo(P * K, (M - 1) * (N - 1)) * expo(P, M + N - 1)) % 10007);
    }

    return 0;
}