Cod sursa(job #2033589)

Utilizator aditoma2001Toma Adrian aditoma2001 Data 7 octombrie 2017 00:48:50
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <bits/stdc++.h>
#include <limits>
using namespace std;

typedef unsigned long long ll;

const ll maxx=1999999973;

ifstream f("lgput.in");
ofstream g("lgput.out");
ll putere(ll n,ll p)
{
    ll prod=1,baza=n;
    while (p>1)
    {
        if (p%2==1) {prod=(prod*baza)%maxx; p--;}
        baza=(baza*baza)%maxx;
        p/=2;
    }
    return (baza*prod)%maxx;
}

int main()
{
    ll n,p;
    f>>n>>p;
    g<<putere(n,p);
    return 0;
}