Cod sursa(job #904846)

Utilizator peter_aPeter Agnes peter_a Data 4 martie 2013 21:37:14
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#define R9 1999999973

using namespace std;

long long a, b;

ifstream fin("lgput.in");
ofstream fout("lgput.out");

long long putere(long long a, long long b) {
    long long r = 1;
    while (b != 0) {
        if (b % 2 == 1)
            r = (r * a) % R9;
        a = (a * a) % R9;
        b /= 2;
    }
    return r;
}

int main() {
    fin >> a >> b;
    fout << putere(a, b);
    return 0;
}