Cod sursa(job #638385)

Utilizator mathboyDragos-Alin Rotaru mathboy Data 20 noiembrie 2011 20:43:41
Problema Matrice5 Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.55 kb
#include <cstdio>

#define mod 10007
#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;
}
int main() {


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

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

		scanf("%d %d %d %d\n", &n, &m, &p, &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;
}