Cod sursa(job #897924)

Utilizator robertc1Robert Ciobotaru robertc1 Data 27 februarie 2013 22:59:22
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.33 kb
#include <fstream>
using namespace std;

ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
    long long n,p,e;
    fin>>n;
    fin>>e;
    p=n;
    e--;
    while(e>1)
    {
        if(e%2==0){p=p*p;e=e/2;}
        else {p=p*n;e--;}
        p=p%1999999973;
    }
    fout<<p<<'\n';
    return 0;
}