Cod sursa(job #2240012)

Utilizator Spuky9Matei Vlad Spuky9 Data 12 septembrie 2018 10:09:19
Problema Matrice5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <cstdio>

using namespace std;

int exp (int a, int b)
{
    if(!b)
        return 1;
    else
    {
        int c=exp(a,b/2);

        if(b%2==0)
            return c*c%10007;
        else
            return c*c%10007*a%10007;
    }
}

int main()
{
    freopen("matrice5.in","r",stdin);
    freopen("matrice5.out","w",stdout);
    int n,m,p,k,t,rez,aux;

    scanf("%d",&t);

    for(int i=1; i<=t; i++)
    {
        scanf("%d %d %d %d",&n,&m,&p,&k);

        //p*k ^ (n-1)(m-1)
        rez = exp(p*k, (n-1)*(m-1));

        // * p^(n+m-1)
		aux = (n+m-1);
        for(int j=1; j<=aux; j++)
        {
            rez = rez * p;
            rez = rez % 10007;
        }

        printf("%d \n",rez);
    }
    return 0;
}