Cod sursa(job #2089537)

Utilizator mateis2017Matei Sotcan mateis2017 Data 16 decembrie 2017 17:59:20
Problema Matrice5 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>

using namespace std;
ifstream in("matrice5.in");
ofstream out("matrice5.out");

long long expow(long long a, long long b, long long mod) {
    long long pod = 1;
                        while (b> 0) {
                                if (b % 2)
                                        pod = pod * a % mod;
                                                    a = a * a % mod;
                                                            b /= 2;
    }
    return pod;
}

int main()
{
    int t, n, m, p, k;
    in >> t;
    for (int i = 1; i <= t; i++)
    {
        in >> n >> m >> p >> k;
        out << expow(k * p, (n - 1) * (m - 1), 10007) * expow(p, n + m - 1, 10007) % 10007 << '\n';
    }
    return 0;
}