Cod sursa(job #2761857)

Utilizator TitanVSirbu Vlad stefan TitanV Data 4 iulie 2021 12:44:17
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream in("lgput.in");
ofstream out("lgput.out");

int main()
{

    long long x, p, c=1;
    in>>x>>p;

    while(p>0)
    {

        if(p%2==1)
        c=x*c%1999999973;

        x*=x;
        x%=1999999973;
        p/=2;
    }



    out<<c;

    return 0;
}



/*
int main()
{

    long long x, p, c=1;
    in>>x>>p;

    if(p==1)
        c=1;
    else if(p==0)
        x=1;
    else
        while(p>1)
        {
            if(p%2==0)
            {
                x*=x;
                p/=2;
            }
            else
            {
                x=x*c;
                x*=x;
                p=(p-1)/2;
            }

        }




    out<<x*c;

    return 0;
}
*/