Cod sursa(job #2285898)

Utilizator DeniszPop Denis Denisz Data 19 noiembrie 2018 14:55:29
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <fstream>

using namespace std;

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

    return 0;
}