Pagini recente » Rating Melintioi George Alexandru (MAlex2019) | Cod sursa (job #3309278) | Cod sursa (job #1681372) | Rating Andrei (andreiulian) | Cod sursa (job #3304856)
#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;
}