Cod sursa(job #2028648)
| Utilizator | Data | 28 septembrie 2017 11:30:09 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <stdio.h>
using namespace std;
int main()
{
FILE *in, *out;
in = fopen("lgput.in", "r");
out = fopen("lgput.out", "w");
long long a, n, y=1, rez=1;
const long long N=1999999973;
fscanf(in, "%lld%lld", &a, &n);
while(n>1){
if(n%2==0){
a=(a*a)%N;
n/=2;
}
else{
y=(a*y)%N;
a=(a*a)%N;
n=(n-1)/2;
}
}
a=(a*y)%N;
fprintf(out, "%lld", a);
return 0;
}
