Cod sursa(job #3275846)

Utilizator TheDasherAdrian Augustin TheDasher Data 11 februarie 2025 20:28:25
Problema Matrice5 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;

const int MOD = 10007;

long long power(long long base, long long exp, long long mod) {
    long long result = 1;
    while (exp) {
        if (exp % 2) result = (result * base) % mod;
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

int main() {
    ifstream fin("matrice5.in");
    ofstream fout("matrice5.out");

    int T;
    fin >> T;

    while (T--) {
        int N, M, P, K;
        fin >> N >> M >> P >> K;

        // Numărul total de matrici modulo 10007
        fout << power(P, N * M, MOD) << "\n";
    }

    return 0;
}