Cod sursa(job #2089540)
Utilizator | Vlad - Gabriel Iftimescu ezioconnor | Data | 16 decembrie 2017 18:00:12 |
---|---|---|---|
Problema | Matrice5 | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.68 kb |
#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;
}