Cod sursa(job #3131847)
| Utilizator | Data | 21 mai 2023 19:55:14 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <stdio.h>
#include <math.h>
double exp_log_rec(double 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(){
double n;
unsigned p;
freopen("lgput.in" , "r" , stdin);
freopen("lgput.out" , "w" , stdout);
if(scanf("%lf %d" , &n , &p) == 2){
printf("%d" , (unsigned)exp_log_rec(n,p)%1999999973);
//printf("%ld" , sizeof(unsigned long));
}
return 0;
}