Cod sursa(job #1844025)

Utilizator vladm98Munteanu Vlad vladm98 Data 9 ianuarie 2017 17:37:01
Problema Matrice5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>

using namespace std;
int modulo = 10007;
int putere (int a, int b)
{
    int raspuns = 1;
    while (b)
    {
        if (b%2)
        {
            --b;
            raspuns = (raspuns*a)%modulo;
        }
        else
        {
            b/=2;
            a = (a*a)%modulo;
        }
    }
    return raspuns;
}
int main()
{
    ifstream fin ("matrice.in");
    ofstream fout ("matrice.out");
    int t, n, m, p, k;
    fin >> t;
    while (t--)
    {
        fin >> n >> m >> p >> k;
        fout << (putere(k, (n-1)*(m-1))*putere(p, n*m))%modulo << '\n';
    }
    return 0;
}