Cod sursa(job #2567696)

Utilizator chriss_b_001Cristian Benghe chriss_b_001 Data 3 martie 2020 18:25:44
Problema Matrice5 Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f("matrice5.in");
ofstream g("matrice5.out");

const int MOD = 10007;

long long power(long long x, long long n)
{
    long long val = 1, a = x;
    while(n > 0)
        if(n % 2 == 0)
        {
            a = a * a % MOD;
            n /= 2;
        }
        else
        {
            val = val * a % MOD;
            n--;
        }
    return val;
}

int main()
{
    int N, M, P, K, T;
    f >> T;///Pt n-1 si m-1 putem pune orice nr
    for(int i = 1; i <= T; i++)
    {
        f >> N >> M >> P >> K;
        int p = K * P % MOD;
        g << 1LL * power(p, (N - 1) * (M - 1)) * power(P, M + N - 1) % MOD << '\n';
    }

    return 0;
}