Cod sursa(job #2569265)

Utilizator GRalyGoia Raluca GRaly Data 4 martie 2020 11:41:18
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.31 kb
#include <fstream>

using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
    int p=1,m,n,exp;
    fin>>n>>exp;
    m=1999999973;
    while(exp)
    {
        if(exp%2==1)
            p=(p*n)%m;
        n=(n*n)%m;
        exp/=2;
    }
    fout<<p;
    return 0;
}