Cod sursa(job #2033575)
Utilizator | Data | 7 octombrie 2017 00:17:21 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ifstream f("lgput.in");
ofstream g("lgput.out");
ll putere(ll n,ll p)
{
ll prod=1,baza=n;
while (p>0)
{
if (p!=1) baza=(baza*baza);
if (p%2==1&&p!=1) { prod=(prod*n); p--;}
p/=2;
}
return (baza*prod)%1999999973;
}
int main()
{
ll n,p;
f>>n>>p;
g<<putere(n,p);
return 0;
}