Cod sursa(job #1921125)

Utilizator PopeangaMihneaPopeanga Mihnea- Stefan PopeangaMihnea Data 10 martie 2017 11:27:32
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const int c=1999999973;
unsigned long long  a, p, n;
int main()
{
    fin>>a>>n;
    p=1;
    while(n>0)
    {
        if(n%2==1)
        {
            p=p*a%c;
            --n;
        }
        else
        {
            a=a*a%c;
            n=n/2;
        }
    }
    fout<<p%c<<"\n";
}