Cod sursa(job #625321)
Utilizator | Data | 24 octombrie 2011 11:52:29 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int n,p;
int fastexp(int b, int n)
{
if(n==0) return 1;
if(n<0) return (1/fastexp(x,-n));
if(n%2)
{ int q=fastexp(x,(n-1)/2);
return x*q*q;
}
int q=fastexp(x,n/2);
return q*q;
}
int main()
{
f>>n>>p;
g<<fastexp(x,p);
f.close(); g.close();
return 0;
}