Cod sursa(job #2293651)

Utilizator flaviu_2001Craciun Ioan-Flaviu flaviu_2001 Data 1 decembrie 2018 13:36:51
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <bits/stdc++.h>
#define ff first
#define ss second

using namespace std;
typedef long long ll;
typedef long double ld;

const string file = "matrice5";
const ll INF = 9223372036854775807ll;
const int inf = 2147483647, M = 10007;

int pw(int x, int y)
{
    x %= M;
    int p = 1;
    while(y)
        if(y%2==0){
            x = (x*x)%M;
            y /= 2;
        }else{
            p = (p*x)%M;
            --y;
        }
    return p;
}

int main()
{
    ifstream fin (file+".in");
    ofstream fout (file+".out");
    int t;
    fin >> t;
    while(t--){
        int n, m, p, k;
        fin >> n >> m >> p >> k;
        fout << (pw(p*k, (n-1)*(m-1))*pw(p, n+m-1))%M << "\n";
    }
    return 0;
}