Cod sursa(job #2089531)

Utilizator Iorgus08Iorgus Serghei Cicala Iorgus08 Data 16 decembrie 2017 17:55:44
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <bits/stdc++.h>

using namespace std;

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

#define mod 10007

int pow(int a,int b)
{
    long long n,p,x=1;
    n=a;
    p=b;
    while (p)
    {
        if (p%2==0)
        {
            p=p/2;
            n=(n*n)%mod;
        }
        else
        {
            p--;
            x=(x*n)%mod;
        }
    }
    return x;
}
int main()
{
    int t,i,n,m,k,p;
    in>>t;
    for(i=1; i<=t; i++)
    {
        in>>n>>m>>p>>k;
        out<<((pow(p*k,(n-1)*(m-1))%mod)*(pow(p,n+m-1)%mod))%mod<<'\n';
    }
    return 0;
}