Cod sursa(job #3136189)
| Utilizator | Data | 5 iunie 2023 16:43:33 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#define CONSTANT 1999999973
int LogNPower(int base, int exponent) {
int result = 1;
for(int index = 1; index <= exponent; index <<= 1) {
if(exponent & index) {
result = (result * base) % CONSTANT;
}
base = (base * base) % CONSTANT;
}
return result;
}
int main()
{
int base, exponent;
freopen("input.txt","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &base, &exponent);
printf("%d", LogNPower(base, exponent));
return 0;
}
