Cod sursa(job #3304856)

Utilizator unknowuserBarat David Pavel unknowuser Data 28 iulie 2025 10:10:58
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
using namespace std;

const int MODULO = 10007;

ifstream inFile("matrice5.in");
ofstream outFile("matrice5.out");

int power_modulo(int base, int exponent) {
    if (exponent == 1) return base;
    int result = power_modulo(base, exponent / 2);
    result = (result * result) % MODULO;
    if (exponent % 2 == 1) {
        result = (result * base) % MODULO;
    }
    return result;
}

int main() {
    int testCount, rows, cols, multiplier, step;
    inFile >> testCount;

    for (int currentTest = 0; currentTest < testCount; currentTest++) {
        inFile >> rows >> cols >> step >> multiplier;

        int firstPart = power_modulo((step * multiplier) % MODULO, (rows - 1) * (cols - 1));
        int secondPart = power_modulo(step, rows + cols - 1);

        outFile << (firstPart * secondPart) % MODULO << '\n';
    }

    return 0;
}