Cod sursa(job #1278880)

Utilizator felixiPuscasu Felix felixi Data 29 noiembrie 2014 14:57:56
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
///   InfoArena ~ Matrice5

#include <fstream>

using namespace std;

ifstream in("matrice5.in");
ofstream out("matrice5.out");

const int MOD = 10007;

long long putere(long long a, long long p) {
    int R= 1;
    while( p != 0 ) {
        if( p%2 == 1 ) {
            R= (R*a) % MOD;
        }
        p>>= 1;
        a= (a*a) % MOD;
    }
    return R;
}

int main() {
    int T, N, M, P, K;
    in >> T;
    for( int t= 0;  t<T;  ++t ) {
        in >> N >> M >> P >> K;
        int A= putere( P*K, (N-1)*(M-1) );
        int B= putere( P,   (N+M-1) );
        out << (A*B) % MOD << '\n';
    }
    return 0;
}