Pagini recente » Cod sursa (job #722954) | Cod sursa (job #1220967) | Cod sursa (job #549715) | Cod sursa (job #685675) | Cod sursa (job #635992)
Cod sursa(job #635992)
#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;
}