Cod sursa(job #2608460)

Utilizator alexboat10759Alex Mateescu alexboat10759 Data 1 mai 2020 13:15:04
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>

using namespace std;

long long int n,p,rez=1,a;
const int nr = 1999999973;

int ridput(long long int n,long long int p)
{
    long long int a = n;
    long long int rez=1;

    for(int i=0; (1<<i) <= p; i++)
    {
        if(((1<<i) & p))
        {
            rez=(rez*a)%nr;
        }
        a=(a*a)%nr;
    }
    return rez;
}

int main()
{
    ifstream cin("lgput.in");
    ofstream cout("lgput.out");


    cin>>n>>p;
    cout<<ridput(n,p);


    return 0;
}