Pagini recente » Cod sursa (job #729091) | Cod sursa (job #1067149) | Cod sursa (job #1498318) | Cod sursa (job #2558381) | Cod sursa (job #2567121)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ( "matrice5.in" );
ofstream g ( "matrice5.out" );
int MOD=10007;
int powlg (int x,int p )
{
long long v = 1, a = x;
while ( p > 0 )
{
while ( p % 2 == 0 )
{
a = a * a % MOD;
p /= 2;
}
v = v * a % MOD;
p--;
}
return v;
}
int main()
{
int T, N, M, K, P;
f >> T;
while ( T-- )
{
f >> N >> M >> P >> K;
long long rez = powlg ( K * P, ( M - 1 ) * ( N - 1 ) ) * powlg ( P, N + M - 1 ) % MOD;
g << rez << '\n';
}
return 0;
}