Cod sursa(job #2002979)
Utilizator | Data | 21 iulie 2017 12:54:53 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.32 kb |
#include <stdio.h>
long long N, P, rez;
const int R = 1999999973;
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%lld %lld", &N, &P);
rez = 1;
while(P != 0) {
if(P % 2 == 1) {
rez = (rez * N) % R;
}
P /= 2;
N = (N * N) % R;
}
printf("%lld", rez);
return 0;
}