Cod sursa(job #2640641)

Utilizator flv.ghGherasim Flavius-Sebastian flv.gh Data 7 august 2020 10:40:40
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <fstream>

using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,p,rasp,rest=1;
int main()
{
    f>>n>>p;
    if(p==0)
    {
        g<<1;
        return 0;
    }
    while(p>1)
    {
        if(p%2==0)
        {
            n=n*n%1999999973;
        }
        else
        {
            rest=n*rest%1999999973;
            n=n*n%1999999973;
        }
        p=p/2;
    }
    rasp=n*rest%1999999973;
    g<<rasp;
    return 0;
}