Cod sursa(job #638388)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 20 noiembrie 2011 20:46:04
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.87 kb
#include <cstdio>

#define mod 10007
#define DIM2 8192
#define ll long long
using namespace std;

ll lgput(ll a, ll b) {
	ll rez = 1;
	while(b)
      { 
            if(b%2==1)
            rez=rez*a%mod;
			a=a*a%mod;
			b/=2;
         }
      return rez;
}
char vec[DIM2];
int poz;
void cit(int &x)   
{   
  x=0;   
  while(vec[poz]<'0' || vec[poz]>'9')   
       if(++poz==DIM2) fread(vec,1,DIM2,stdin),poz=0;   
  
    while(vec[poz]>='0' && vec[poz]<='9')   
    {   
        x=x*10+vec[poz]-'0';   
        if(++poz==DIM2) fread(vec, 1, DIM2, stdin),poz=0;   
    }  
}   
int main() {


	freopen("matrice5.in", "r", stdin);
	freopen("matrice5.out", "w", stdout);

	int T, n,m,p,k;
	for(scanf("%d", &T); T--; ) {

		cit(n); cit(m); cit(p); cit(k);
		//p^(n*m);
		ll res = lgput(k, 1LL * (n-1)*(m-1));
		res = (res * lgput(p, 1LL * (n*m))) % mod;
		printf("%lld\n", res);
	}
	return 0;
}