Cod sursa(job #951744)
Utilizator | Data | 21 mai 2013 16:16:18 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <fstream>
using namespace std;
long long exp(long long n, long long e)
{
int rez;
if (e<=1)
return n;
rez=exp(n,e>>1);
rez*=rez;
if (e&1)
rez*=n;
return rez;
}
int main()
{
long long n,p;
ifstream f1("lgput.in");
ofstream f2("lgput.out");
f1>>n>>p;
f2<<exp(n,p);
f1.close();
f2.close();
return 0;
}