Cod sursa(job #2033588)
| Utilizator | Data | 7 octombrie 2017 00:47:58 | |
|---|---|---|---|
| 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 int_fast64_t 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;
}
