Cod sursa(job #233917)
Utilizator | Data | 19 decembrie 2008 18:14:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<fstream.h>
unsigned long n;
long double hatvany(unsigned long x){
if(x==1)
return n;
else
if(x%2==0)
return hatvany(x/2)*hatvany(x/2);
if(x%2==1)
return hatvany(x/2)*hatvany(x/2)*n; }
void main(void) {
ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long p;
f>>n>>p;
g<<hatvany(p); }