Pagini recente » Cod sursa (job #430283) | Cod sursa (job #862225) | Cod sursa (job #1933734) | Cod sursa (job #385579) | Cod sursa (job #681813)
Cod sursa(job #681813)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long long putere (int N, int P) {
if (P == 1)
return N;
if (P % 2 == 0) {
int x = putere(N, P/2);
return x * x;
}
else {
int x = putere(N, (P-1)/2);
return N * x * x;
}
}
int main () {
FILE *f_in = fopen("lgput.in", "r");
FILE *f_out = fopen("lgput.out", "w");
int N, P;
fscanf(f_in, "%d %d", &N, &P);
fprintf(f_out, "%lld", putere(N, P));
fclose(f_in);
fclose(f_out);
return 0;
}