Cod sursa(job #1235285)

Utilizator gedicaAlpaca Gedit gedica Data 29 septembrie 2014 13:36:08
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>

using namespace std;

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

int MOD= 10007;

int putere( int a, int b )
{
    int x=a, chestie=1;
    for( int i=0; (1<<i)<=b; ++i )
    {
        if( ((1<<i)&b)>0 )
           {
               chestie= ( chestie*x )%MOD;
           }
        x=(x*x)%MOD;
    }
    return chestie;
}

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