Cod sursa(job #2947534)

Utilizator raileanu-alin-gabrielRaileanu Alin-Gabriel raileanu-alin-gabriel Data 26 noiembrie 2022 11:39:02
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
const int MOD=10007;

using namespace std;
ifstream fin("matrice5.in");
ofstream fout("matrice5.out");

void test();
long long pt(int a, int b)
{
  if(b==0) return 1;
  if(b%2==0)
  {
    long long ptt=pt(a, b/2);
    return (ptt*ptt)%MOD;
  }
  return (pt(a, b-1)*a)%MOD;
}

int main()
{
  ios_base::sync_with_stdio(false);
  fin.tie(0);
  int t; fin>>t;
  while(t--) test();
}

void test()
{
  long long x, n, m, p, k, y;
  fin>>n>>m>>p>>k;
  x=pt(k*p, (n-1)*(m-1));
  y=pt(p, m+n-1);
  fout<<(x*y)%MOD<<'\n';
}