Cod sursa(job #3227536)
| Utilizator | Data | 1 mai 2024 19:09:41 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <stdio.h>
long ExpLogRec(long x, long n) {
if (n < 0) {
return 1 / ExpLogRec(x, -n);
} else if (n == 0) {
return 1;
} else if (n % 2 == 0) {
return ExpLogRec(x * x, n / 2);
} else if (n % 2 == 1) {
return x * ExpLogRec(x * x, (n - 1) / 2);
}
return 0;
}
int main() {
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
long nr = 0;
long exp = 0;
scanf("%ld%ld", &nr, &exp);
printf("%ld", ExpLogRec(nr, exp) % 1999999973);
return 0;
}
