Cod sursa(job #3131842)
| Utilizator | Data | 21 mai 2023 19:46:39 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#include <math.h>
float exp_log_rec(float n, unsigned p){
if(p < 0) return exp_log_rec(1.0 / n, -p);
if(p == 0) return 1;
if(p % 2 == 0) return exp_log_rec(n*n, p/2);
if(p % 2 == 1) return n * exp_log_rec(n*n, p/2);
return 0;
}
int main(){
float n;
unsigned p;
freopen("lgput.in" , "r" , stdin);
freopen("lgput.out" , "w" , stdout);
if(scanf("%f %d" , &n , &p) == 2){
printf("%d" , (unsigned)exp_log_rec(n,p)%1999999973);
//printf("%lf" , pow(n,p)%1999999973);
}
return 0;
}