Cod sursa(job #1414351)

Utilizator pulseOvidiu Giorgi pulse Data 2 aprilie 2015 15:48:07
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <fstream>

using namespace std;

const int mod = 1999999973;

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

int n, p;
long long a, sol;

int main()
{
    fin >> n >> p;
    a = n;
    sol = 1;
    for (int i = 0; (1 << i) <= p; i++)
    {
        if (p & (1 << i))
            sol = (sol * a) % mod;
        a = (a * a) % mod;
    }
    fout << sol;
    return 0;
}