Cod sursa(job #953942)

Utilizator SebaRabaRaba Sebastian-Setafan SebaRaba Data 27 mai 2013 20:42:55
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int n_max = 10001;
const int m = 1999999973;

int main()
{
    unsigned int i, Nr, Put;
    long long aux, sol = 1;
    fin>>Nr;fin>>Put;
    aux = Nr;
    for (i = 0; (1<<i) <= Put; ++ i)
    {
        if ( ((1<<i) & Put) > 0)
            sol= (sol * aux) % m;

            aux=(aux * aux) % m;
    }
    fout<<sol;
}