Cod sursa(job #2781520)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 9 octombrie 2021 18:23:59
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>

using namespace std;

ifstream cin ( "matrice5.in" );
ofstream cout ( "matrice5.out" );

#define MOD 10007

int lg_put ( int base, int power ) {
    int answer = 1;
    while ( power > 0 ) {
        if ( power & 1 ) {
            answer = ( answer * base ) % MOD;
        }
        base = ( base * base ) % MOD;
        power >>= 1;
    }
    return answer;
}

int main() {
    int t, n, m, p, k, i;
    cin >> t;
    for ( i = 0; i < t; i++ ) {
        cin >> n >> m >> p >> k;
        cout << ( lg_put(k, ( n - 1 ) * ( m - 1 )) * lg_put(p, n * m) ) % MOD << "\n";
    }
    return 0;
}