Cod sursa(job #1106676)

Utilizator gerd13David Gergely gerd13 Data 13 februarie 2014 00:14:12
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#define MODULO 10007 ;

using namespace std ;

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

int T ;
int N, P, K, M ;

inline long long Verif(int X, int P)
{
    if(P == 0) return 1 ;
    long long t = Verif(X, P/2) ;
    if(P % 2 == 0)
        return t*t%MODULO ;
    return (long long) t * t * X % MODULO ;

}

inline void Solve()
{
    long long X ;
    int real = K * P ;
    X = Verif(real, (N - 1) * (M - 1)) ;
    X = X * Verif(P, N + M - 1) % MODULO ;
    cout << X << '\n' ;
}
int main()
{

    cin >> T ;
    while(T)
    {
        cin >> N >> M >> P >> K ;
        Solve() ;
        -- T ;
    }

    cin.close() ;
    cout.close() ;
    return 0 ;
}