Cod sursa(job #311255)

Utilizator sandyxpSanduleac Dan sandyxp Data 3 mai 2009 10:14:18
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.34 kb
#include <fstream>
using namespace std;

#define NUME "lgput"
#define P  1999999973
ifstream fi(NUME".in");
ofstream fo(NUME".out");

int main()
{
    long long n, q, rez;
    fi >> n >> q;
    rez = 1;
    while (q) {
        if (q & 1) rez = (rez * n) % P, q--;
        else n = (n*n) % P, q /= 2;
    }
    fo << rez << endl;
    return 0;
}