Cod sursa(job #2955316)

Utilizator stefan05Vasilache Stefan stefan05 Data 16 decembrie 2022 18:43:11
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>

#define LL long long int
#define MOD 10007

using namespace std;

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

int t;
int n, m, k, p;
int q;

LL explog(LL, LL);

int main()
{
    fin >>t;
    for (q = 1; q <= t; ++q)
    {
        fin >>n>>m>>p>>k;
        fout <<(explog(p*k, (n-1)*(m-1)) * explog(p, n+m-1)) % MOD<<'\n';
    }
    fout.close();
    return 0;
}

LL explog(LL a, LL x)
{
    if (!x) return 1;
    LL aux = explog(a, x/2) % MOD;
    return (x%2? (aux*aux)%MOD*(a%MOD): aux*aux) % MOD;
}