Cod sursa(job #1899741)
Utilizator | Data | 2 martie 2017 21:58:33 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <cstdio>
using namespace std;
long long a, n, p;
int main ()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld%lld", &a, &n);
p=1;
while (n){
if (n%2==1){
p=(p*a)%1999999973;
--n;
}
else{
a=(a*a)%1999999973;;
n/=2;
}
}
printf("%lld", p);
return 0;
}