Cod sursa(job #1509195)

Utilizator lucametehauDart Monkey lucametehau Data 23 octombrie 2015 16:25:59
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long int var;

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

const var N = 1999999973;

var pow(var x, var p)
{
    var out = 1;

    while(p)
    {
        if (p % 2 == 1)
        {
            out = (out * x) % N;
            p--;
        }
        x = (x * x) % N;
        p = p / 2;
    }
    return out;
}
int main()
{
    var n, p;
    in >> n >> p;
    out << pow(n, p);

    return 0;
}