Pagini recente » Cod sursa (job #1508420) | Cod sursa (job #743444) | Cod sursa (job #270262) | Cod sursa (job #2285352) | Cod sursa (job #636945)
Cod sursa(job #636945)
#include<fstream>
using namespace std;
#define MOD 10007
long long z=MOD;
long long put(long long x,long long y)
{
long long w;
if(y==1)
return x;
else if(y%2==0)
{
w=put(x,y/2);
return (w*w)%z;
}
else
{
w=put(x,y-1)%z;
return (w*x)%z;
}
}
int N;
int main()
{
ifstream fin("matrice5.in");
ofstream fout("matrice5.out");
int x,y,w,e;
fin>>N;
for(int i=1;i<=N;++i)
{
fin>>x>>y>>w>>e;
if(x!=1&&y!=1)
fout<<(put(w*e,(x-1)*(y-1)))*put(w,x*y-(x-1)*(y-1))%MOD;
else if(x==1)
{
fout<<((put(x-1,w*e)*w)%MOD);
}
else
{
fout<<((put(y-1,w*e)*w)%MOD);
}
}
}