Cod sursa(job #635992)

Utilizator ProtomanAndrei Purice Protoman Data 19 noiembrie 2011 16:09:23
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda .com 2011 Marime 0.6 kb
#include <algorithm>
#include <iostream>
#include <fstream>

#define restRez 10007

using namespace std;

inline int putere(int nr, int exp)
{
	int r = 1;
	
	for (; exp > 1; exp /= 2)
	{
		if (exp & 1)
			r = (r * nr) % restRez;
		nr = (nr * nr) % restRez;
	}

	return (nr * r) % restRez;
}

int main()
{
	ifstream cin("matrice5.in");
	ofstream cout("matrice5.out");

	int testCases;
	for (cin >> testCases; testCases; testCases--)
	{
		int n, m, p, k;
		cin >> n >> m >> p >> k;

		cout << (putere(p, n * m) * putere(k, (n - 1) * (m - 1))) % restRez << '\n';
	}

	return 0;
}