Pagini recente » Cod sursa (job #743130) | Cod sursa (job #846942) | Cod sursa (job #1583644) | Cod sursa (job #1614885) | Cod sursa (job #636950)
Cod sursa(job #636950)
Utilizator |
L Greg Lgreg |
Data |
20 noiembrie 2011 04:40:13 |
Problema |
Matrice5 |
Scor |
100 |
Compilator |
cpp |
Status |
done |
Runda |
.com 2011 |
Marime |
0.94 kb |
#include<fstream>
using namespace std;
#define MOD 10007
long long z=MOD;
inline long long put(long long N,long long K)
{//printf("%d %d\n",N,K);
long long rez=1;
long long M=N;
for(int i=0;1LL*(1<<i)<=K;++i)
{
if((1<<i)&K)
{//printf("%d\n",i);
rez*=M;
rez%=MOD;
}
M*=M;
M%=MOD;
}
return rez;
}
long long N;
int main()
{
ifstream fin("matrice5.in");
ofstream fout("matrice5.out");
long long 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<<"\n";
else if(x==1&y==1)
{
fout<<w*e%MOD<<"\n";
}
else if(x==1)
{
fout<<((put(x-1,w*e)*w)%MOD)<<"\n";
}
else
{
fout<<((put(y-1,w*e)*w)%MOD)<<"\n";
}
}
}