Cod sursa(job #2567121)

Utilizator SergiuS3003Sergiu Stancu Nicolae SergiuS3003 Data 3 martie 2020 15:16:37
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda forta10b Marime 0.65 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ( "matrice5.in" );
ofstream g ( "matrice5.out" );
int MOD=10007;
int powlg (int x,int p )
{
    long long v = 1, a = x;

    while ( p > 0 )
    {
        while ( p % 2 == 0 )
        {
            a = a * a % MOD;
            p /= 2;
        }

        v = v * a % MOD;
        p--;
    }

    return v;
}
int main()
{
    int T, N, M, K, P;
    f >> T;

    while ( T-- )
    {
        f >> N >> M >> P >> K;
        long long rez = powlg ( K * P, ( M - 1 ) * ( N - 1 ) ) * powlg ( P, N + M - 1 ) % MOD;
        g << rez << '\n';
    }

    return 0;
}