Pagini recente » Cod sursa (job #2716747) | Cod sursa (job #3247685) | Cod sursa (job #204919) | Cod sursa (job #1044669) | Cod sursa (job #2223884)
#include<fstream>
#include<cstring>
#include<iostream>
#define DN 2005
#define M 10007
using namespace std;
ifstream fin("matrice5.in");
ofstream fout("matrice5.out");
int t,n,m,p,k,rez,f;
int put(int a,int b)
{
int p=1,c=a,r=1;
while(p<=b)
{
if(p&b)
r=(r*c)%M;
c=(c*c)%M;
p=p*2;
}
return r;
}
int main()
{
fin>>t;
while(t--)
{
fin>>n>>m>>p>>k;
rez=1;
rez=put((k*p)%M,m-1);
rez=(rez*p)%M;
// cout<<rez<<'\n';
if(n==1)
{
fout<<rez<<'\n';
continue;
}
f=rez;
rez=put(rez,n-1);
rez=(rez*put(p,m))%M;
fout<<rez<<'\n';
}
}