Cod sursa(job #1268327)
| Utilizator | Data | 20 noiembrie 2014 20:44:08 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <stdio.h>
FILE *fin, *fout;
unsigned long long a, b;
unsigned long long power(unsigned long long x, unsigned long long y)
{
if(y == 0) return 1;
if(y == 1) return x;
if(y%2 == 0) return power(x*x, y/2);
return x*power(x*x, (y-1)/2);
}
int main()
{
fin = fopen("lgput.in", "r");
fout = fopen("lgput.out", "w");
fscanf(fin, "%lld%lld", &a, &b);
fprintf(fout, "%lld", power(a, b));
fclose(fin);
fclose(fout);
return 0;
}
