Pagini recente » Cod sursa (job #398136) | Cod sursa (job #2849327) | Cod sursa (job #1743820) | Cod sursa (job #2183497) | Cod sursa (job #2089540)
#include <fstream>
using namespace std;
ifstream in("matrice5.in");
ofstream out("matrice5.out");
int putere(int a, int b)
{
long long n, p, x = 1;
n = a;
p = b;
while (p)
{
if (p % 2 == 0)
{
p = p / 2;
n = (n * n) % 10007;
}
else
{
p--;
x = (x * n) % 10007;
}
}
return x;
}
int main()
{
int n, m, p, k, a, t, i;
in >> t;
for (i = 1; i <= t; ++i)
{
in >> n >> m >> p >> k;
out<<((putere(p * k, (n - 1) * (m - 1)) % 10007) * (putere(p, n + m - 1) % 10007)) % 10007<<'\n';
}
return 0;
}