Pagini recente » Cod sursa (job #480085) | Cod sursa (job #671966) | Cod sursa (job #3220862) | Cod sursa (job #328399) | Cod sursa (job #681811)
Cod sursa(job #681811)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
long putere (int N, int P) {
if (P == 0)
return 1;
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, i;
fscanf(f_in, "%d %d", &N, &P);
fprintf(f_out, "%ld", putere(N, P));
fclose(f_in);
fclose(f_out);
return 0;
}