Cod sursa(job #638683)

Utilizator freak93Adrian Budau freak93 Data 21 noiembrie 2011 13:24:27
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <fstream>

using namespace std;

const int mod = 10007;

int log(int x, int y) {
	if (y == 1)
		return x % mod;
	
	int answer = log(x, y / 2);
	answer = (answer * answer) % mod;

	if (y % 2)
		answer *= log(x, 1);
	
	return answer % mod;
}

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

	int T; cin >> T;
	while (T--) {
		int N, M, K, P;
		cin >> N >> M >> P >> K;

		int answer = 1;
		answer = log(K * P, (N - 1) * (M - 1)) * log(P, N + M - 1);
		cout << answer % mod << "\n";
	}
}