Cod sursa(job #1415931)

Utilizator Corina1997Todoran Ana-Corina Corina1997 Data 6 aprilie 2015 21:25:55
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <fstream>
#define MOD 10007
using namespace std;

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

int t;
int n, m, p, k;
int sol;
int Fact( int a, int b );

int main()
{
    is >> t;
    for ( int i = 1; i <= t; i++ )
    {
        is >> n >> m >> p >> k;
        sol = ( Fact( p, n * m ) * Fact( k, (n-1) * (m-1) ) ) % MOD;
        os << sol << '\n';
    }
    is.close();
    os.close();
    return 0;
}

int Fact( int a, int b )
{
    if ( b == 1 ) return a;
    if ( b == 0 ) return 1;
    int aux = Fact( a, b / 2 );
    aux = ( aux * aux ) % MOD;
    if ( b % 2 )
        aux = (aux * a) % MOD;
    return aux;
}